Skip to content

Commit fe0a95a

Browse files
committed
Initial commit
1 parent a2f6cb0 commit fe0a95a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
int lastVal = INT_MIN;
15+
bool isValidBST(TreeNode* root) {
16+
if (root == NULL) {
17+
return true;
18+
}
19+
if (!isValidBST(root->left)) {
20+
return false;
21+
}
22+
if (lastVal >= root->val) {
23+
return false;
24+
}
25+
lastVal = root->val;
26+
if (!isValidBST(root->right)) {
27+
return false;
28+
}
29+
return true;
30+
}
31+
};

0 commit comments

Comments
 (0)