Skip to content

Commit d2f8529

Browse files
authored
Update to match video's code
Problem: 0098-validate-binary-search-tree Language: C++ Submission URL: https://leetcode.com/problems/validate-binary-search-tree/submissions/883304020/
1 parent 16778ed commit d2f8529

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cpp/0098-validate-binary-search-tree.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
Space: O(n)
88
*/
99

10+
/**
11+
* Definition for a binary tree node.
12+
* struct TreeNode {
13+
* int val;
14+
* TreeNode *left;
15+
* TreeNode *right;
16+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
17+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
18+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
19+
* };
20+
*/
1021
/**
1122
* Definition for a binary tree node.
1223
* struct TreeNode {
@@ -19,6 +30,22 @@
1930
* };
2031
*/
2132
class Solution {
33+
public:
34+
bool isValidBST(TreeNode* root) {
35+
return helper(root, LONG_MIN, LONG_MAX);
36+
}
37+
private:
38+
bool helper(TreeNode* root, long left, long right){
39+
if (!root)
40+
return true;
41+
if (root->val < right && root->val > left){
42+
return helper(root->left, left, root->val) && helper(root->right, root->val, right);
43+
}
44+
return false;
45+
}
46+
};
47+
/*
48+
class Solution {
2249
public:
2350
bool isValidBST(TreeNode* root) {
2451
TreeNode* prev = NULL;
@@ -46,6 +73,7 @@ class Solution {
4673
return true;
4774
}
4875
};
76+
*/
4977

5078
// class Solution {
5179
// public:

0 commit comments

Comments
 (0)