Last active
December 12, 2015 05:09
-
-
Save charlespunk/4719970 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
Implement a function to check is a binary tree is a binary search tree. |
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 validate(Node root){ | |
validate(root, Integer.MIN_VALUE, Integer.MAX_VALUE); | |
} | |
public static boolean validate(Node root, int mix, int max){ | |
if(root == null) return true; | |
else if(root.value <= min || root.value > max) return false; | |
return (validate(root.left, min, root.value) && validate (root.right, root.value, max)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment