Skip to content

Instantly share code, notes, and snippets.

@jyhjuzi
Created July 15, 2014 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyhjuzi/77590c414117f9e4d76d to your computer and use it in GitHub Desktop.
Save jyhjuzi/77590c414117f9e4d76d to your computer and use it in GitHub Desktop.
public class Q4_5{
public static void main(String[] args){
TreeNode root1 = new TreeNode(7,new TreeNode(2,new TreeNode(1),new TreeNode(3,null,new TreeNode(8))),new TreeNode(11));
System.out.println(isBST(root1,Integer.MAX_VALUE,Integer.MIN_VALUE));
}
static boolean isBST(TreeNode root, int max, int min){
if(root == null)
return true;
int value = (Integer) root.value;
if(value>max || value<min)
return false;
if(!isBST(root.left,value,min))
return false;
if(!isBST(root.right,max,value))
return false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment