Skip to content

Commit 7ee5087

Browse files
Merge pull request #155 from russianalfred/patch-1
第二周作业#27
2 parents c7961b0 + 1f5e79a commit 7ee5087

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Week_01/id_27/leetcode_783_027

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)