题目:
题解:
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/
bool isValid(struct TreeNode * root,long left,long right){if(!root){return true;}long x = root->val;return left<x && x<right && isValid(root->left,left,x) && isValid(root->right,x,right);
}
bool isValidBST(struct TreeNode* root) {return isValid(root,LONG_MIN,LONG_MAX);
}