/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool judge(struct TreeNode* root,long* pre){
if(!root) return true;
bool a=judge(root->left,pre);
if(root->val <= *pre) return false;
*pre=root->val;
bool b=judge(root->right,pre);
return a&&b;
}
bool isValidBST(struct TreeNode* root) {
if(!root) return true;
if(!root->left&&!root->right ) return true;
long pre=LONG_MIN;
return judge(root,&pre);
}
结果:
标签:pre,return,struct,验证,二叉,98,bool,TreeNode,root From: https://www.cnblogs.com/llllmz/p/18056397