We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9c1260c commit 6297829Copy full SHA for 6297829
validate-binary-search-tree/PDKhan.cpp
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ public:
3
+ bool search(TreeNode* root, long min, long max){
4
+ if(root == NULL)
5
+ return true;
6
+
7
+ if(root->val <= min || root->val >= max)
8
+ return false;
9
10
+ if(search(root->left, min, root->val) == false)
11
12
13
+ if(search(root->right, root->val, max) == false)
14
15
16
17
+ }
18
19
+ bool isValidBST(TreeNode* root) {
20
+ return search(root, (long)INT_MIN-1, (long)INT_MAX+1);
21
22
+ };
0 commit comments