[second]Validate Binary Search Tree
bool isValidBST(TreeNode *root) {
// Note: The Solution object is instantiated only once and is reused by each test case.
return helper(root,INT_MIN,INT_MAX);
}
bool helper(TreeNode* root,int lower,int upper)
{
if(!root)
return true;
if(root->val<=lower||root->val>=upper)
return false;
return helper(root->left,lower,root->val)&&helper(root->right,root->val,upper);
}
浙公网安备 33010602011771号