We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c7961b0 + 1f5e79a commit 7ee5087Copy full SHA for 7ee5087
1 file changed
Week_01/id_27/leetcode_783_027
@@ -0,0 +1,24 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * struct TreeNode {
4
+ * int val;
5
+ * TreeNode *left;
6
+ * TreeNode *right;
7
+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8
+ * };
9
+ */
10
+class Solution {
11
+public:
12
+ int Res= INT_MAX;
13
+ int Pre = 0;
14
+ int minDiffInBST(TreeNode* root) {
15
+ if(root->left != NULL)
16
+ minDiffInBST(root->left);
17
+ if(Pre > 0)
18
+ Res = min(Res,root->val - Pre);
19
+ Pre = root->val;
20
+ if(root->right != NULL)
21
+ minDiffInBST(root->right);
22
+ return Res;
23
+ }
24
+};
0 commit comments