Skip to content

Instantly share code, notes, and snippets.

@Ray1988
Created March 14, 2013 20:23
Show Gist options
  • Save Ray1988/5164891 to your computer and use it in GitHub Desktop.
Save Ray1988/5164891 to your computer and use it in GitHub Desktop.
Check is a binary tree is binary search tree(improved)
static int lastNum=Integer.miniValue();
public boolean checkBST(TreeNode r){
if(r==null) return true;
if(!checkBST(r.left)) return false;
if(r.data<lastNum) return false;
lastNum=r.data;
if(!checkBST(r.right) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment