Created
September 9, 2014 04:58
-
-
Save sopherwang/42cdefa2ddff3cb6e758 to your computer and use it in GitHub Desktop.
Validate Binary Search Tree
This file contains 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 boolean isValidBST(TreeNode root) | |
{ | |
return isValidate(root, Integer.MIN_VALUE, Integer.MAX_VALUE); | |
} | |
private boolean isValidate(TreeNode root, int min, int max) | |
{ | |
if (root == null) | |
{ | |
return true; | |
} | |
if (min >= root.val || max <= root.val) | |
{ | |
return false; | |
} | |
return isValidate(root.left, min, root.val) && isValidate(root.right, root.val, max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment