标签:https null heap abs public pre leetcode mini href
Leetcode:530. 二叉搜索树的最小绝对差
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int min=INT_MAX;
TreeNode* preNode=NULL;
void DFS(TreeNode* root){
if(root==NULL) return;
DFS(root->left);
if(preNode!=NULL&&abs(root->val-preNode->val)<min) min=abs(root->val-preNode->val);
preNode=root;
DFS(root->right);
}
int getMinimumDifference(TreeNode* root) {
DFS(root);
return min;
}
};
标签:https null heap abs public pre leetcode mini href
原文地址:https://www.cnblogs.com/cell-coder/p/12379863.html