Created
November 8, 2015 19:24
-
-
Save ejcer/0a824ac846ee5c832de8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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