/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
return isPartialBST(root, INT_MIN, INT_MAX);
}
bool isPartialBST(TreeNode* n, int minVal, int maxVal)
{
if (!n) return true;
if (n->val > minVal && n->val < maxVal)
{
return isPartialBST(n->left, minVal, n->val) && isPartialBST(n->right, n->val, maxVal);
}
return false;
}
};
[Leetcode] Validate Binary Search Tree
最新推荐文章于 2020-10-15 09:59:45 发布