/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void inorder(struct TreeNode* root,int* t,int* pre){
if(!root) return;
inorder(root->left,t,pre);
int x=abs(root->val-*pre);
if(x<*t) *t=x;
*pre=root->val;
inorder(root->right,t,pre);
}
int getMinimumDifference(struct TreeNode* root) {
int t=INT_MAX;
int pre=INT_MAX;
inorder(root,&t,&pre);
return t;
}
结果:
标签:pre,TreeNode,struct,int,inorder,二叉,搜索,530,root From: https://www.cnblogs.com/llllmz/p/18056646