设置一个全局变量记录前一次的值就行比较
public class Main(){
public static boolean checkBST(TreeNode root){
if(root==null)return true;
if(!checkBST(root.left))return false;//检查左子
if(root.value<=pre)return false;//根的值小于等于左子的最大值
//更新最后访问值,检查右子
pre=root.value;
return check(root.right);
}
private static int pre=Integer.MIN_VALUE;
}