Skip to content

Commit 270fbd5

Browse files
authored
530.Minimum Absolute Difference in BST
530.Minimum Absolute Difference in BST
1 parent 68bed7f commit 270fbd5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

getMinimumDifference.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
private:
3+
int diff = INT_MAX;
4+
int minimum = -1;
5+
public:
6+
int getMinimumDifference(TreeNode* root) {
7+
if(root->left) getMinimumDifference(root->left);
8+
if(minimum >=0) diff = min(diff, (root->val - minimum));
9+
minimum = root->val;
10+
if(root->right) getMinimumDifference(root->right);
11+
return diff;
12+
}
13+
14+
};

0 commit comments

Comments
 (0)