/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool inorder(struct TreeNode* root,long* pre){
if(!root) return true;
bool a=inorder(root->left,pre);
if(root->val <= *pre) return false;
*pre=root->val;
bool b=inorder(root->right,pre);
return a&b;
}
bool isValidBST(struct TreeNode* root) {
long pre=LONG_MIN;
return inorder(root,&pre);
}
结果: