Skip to content

Instantly share code, notes, and snippets.

@mountop
Last active August 29, 2015 13:57
//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