Skip to content

Instantly share code, notes, and snippets.

@ejcer
Created November 8, 2015 19:24
Show Gist options
  • Save ejcer/0a824ac846ee5c832de8 to your computer and use it in GitHub Desktop.
Save ejcer/0a824ac846ee5c832de8 to your computer and use it in GitHub Desktop.
public static boolean isBST(Node head){
if(head == null){
return false;
}else{
return isBST(head, Integer.MIN_INTEGER, Integer.MAX_INTEGER);
}
}
private static boolean isBST(Node head, int min, int max){
if(head == null){
return true;
}
if(head.val <= max && head.val > min){
return isBST(head.left, min, head.val) && isBST(head.right, head.val, max);
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment