Created
March 14, 2013 20:23
-
-
Save Ray1988/5164891 to your computer and use it in GitHub Desktop.
Check is a binary tree is binary search tree(improved)
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
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