Last active
August 29, 2015 13:57
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
//in Java | |
public boolean isValidBST(TreeNode root) { | |
if(root == null) return true; | |
return isValidBSTRec(root, Integer.MIN_VALUE, Integer.MAX_VALUE); | |
} | |
public boolean isValidBSTRec(TreeNode root, int min, int max){ | |
if(root == null) return true; | |
if(root.val>min && root.val<max && isValidBSTRec(root.left, min, root.val)&&isValidBSTRec(root.right, root.val, max)) | |
return true; | |
else | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment