Validate Binary Search Tree

 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 }
View Code

 

posted @ 2014-02-06 14:58  krunning  阅读(87)  评论(0编辑  收藏  举报