Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean checkBST(Node root) {
- return checkBSTUtil(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
- }
- boolean checkBSTUtil(Node root, int min, int max){
- if(root == null)
- return true;
- else if(root.data < min || root.data > max)
- return false;
- return (checkBSTUtil(root.left, min, root.data - 1) && checkBSTUtil(root.right,root.data + 1, max));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement