Skip to content

Commit ff7ada1

Browse files
committed
Solution as on 30-09-2022 11:45 pm
1 parent 202166f commit ff7ada1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// 98.✅ Validate Binary Search Tree
2+
3+
class Solution
4+
{
5+
public:
6+
bool helper(TreeNode *root, long mn, long mx)
7+
{
8+
if (!root)
9+
return true;
10+
11+
if (root->val <= mn || root->val >= mx)
12+
return false;
13+
14+
return helper(root->left, mn, root->val) && helper(root->right, root->val, mx);
15+
}
16+
17+
bool isValidBST(TreeNode *root)
18+
{
19+
return helper(root, LONG_MIN, LONG_MAX);
20+
}
21+
};

0 commit comments

Comments
 (0)