题目
题解
public class Solution {
private TreeNode pre = null;
/**
* 给定一个二叉树根节点,请你判断这棵树是不是二叉搜索树
*
*
* @param root TreeNode类
* @return bool布尔型
*/
public boolean isValidBST (TreeNode root) {
if (null == root) {
return false;
}
return inorder(root);
}
public boolean inorder(TreeNode curr) {
if (null == curr) {
return true;
}
boolean isLeftOK = inorder(curr.left);
if (pre != null && pre.val >= curr.val) {
return false;
}
pre = curr;
boolean isRightOK = inorder(curr.right);
return isLeftOK && isRightOK;
}
}
标签:pre,curr,34,boolean,return,必刷,null,inorder,TOP101
From: https://blog.51cto.com/u_16244372/8589603