Skip to content

Commit a973f66

Browse files
committed
Time: 8 ms (94.19%), Space: 21.6 MB (85.86%) - LeetHub
1 parent 74c1a0d commit a973f66

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
bool isValidBST(TreeNode* root, long minval = LLONG_MIN, long maxval = LLONG_MAX) {
15+
if(root == NULL)
16+
return true;
17+
return isValidBST(root->left, minval, root->val) and (minval < root->val and root->val < maxval) and isValidBST(root->right, root->val, maxval);
18+
}
19+
};

0 commit comments

Comments
 (0)