1 public class Solution { 2 public boolean isValidBST(TreeNode root) { 3 return is(root,Integer.MAX_VALUE,Integer.MIN_VALUE); 4 } 5 public boolean is(TreeNode root,int max,int min){ 6 if(root==null) 7 return true; 8 if(root.val<max && root.val>min){ 9 return is(root.left,root.val,min)&&is(root.right,max,root.val); 10 } 11 else return false; 12 } 13 }
原文:http://www.cnblogs.com/krunning/p/3538795.html