关于二叉搜索树验证的递归版本,看到有位大佬的写法感觉真的很妙,这里写博客记录一下
int* last = NULL;
bool isValidBST(TreeNode* root) {
if (root){
if(!isValidBST(root->left)) return false;
if (last && *last>=root->val) return false;
last = &root->val;
if(!isValidBST(root->right)) return false;
return true;
}else return true;
};