class Solution {
TreeNode max;
public boolean isValidBST(TreeNode root) {
if (root == null) return true;
//左
boolean left = isValidBST(root.left);
if(!left) return false;
//中,先写max != null
if(max != null && root.val <= max.val ) return false;
max = root;
//右
boolean right = isValidBST(root.right);
return right;
}
}
class Solution {
TreeNode pre;
int res = Integer.MAX_VALUE;
public int getMinimumDifference(TreeNode root) {
if(root == null) return 0;
gap(root);
return res;
}
public void gap(TreeNode root){
if (root == null)return;
gap(root.left);
if (pre != null ){
res = Math.min(root.val - pre.val, res);
}
pre = root;
gap(root.right);
}
}