98. 验证二叉搜索树

long l = 9223372036854775808; 后面是一个int 类型 的数
long l = 9223372036854775808L; 才是一个long类型的数

class Solution {
    public boolean isValidBST(TreeNode root) {
    	return dfs(root,Integer.MIN_VALUE-100L,Integer.MAX_VALUE+100L);
    }
    public boolean dfs(TreeNode root,long x,long y) {
		if(root == null) return true;
		if(x>root.val||y<root.val) return false;                                        //y 可以等于 root.val x也一样 因为在传参的过程中 已经将数值代入了 
		return dfs(root.left,x,root.val-1L)&dfs(root.right,root.val+1L,y);        //&& 用的太妙了
	}
    }

long 和 int 加减一定要注意 + xxx L 不然会被强行转化位int 类型

原文地址:https://www.cnblogs.com/cznczai/p/11346714.html