Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. boolean checkBST(Node root) {
  2. return checkBSTUtil(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
  3. }
  4.  
  5. boolean checkBSTUtil(Node root, int min, int max){
  6. if(root == null)
  7. return true;
  8. else if(root.data < min || root.data > max)
  9. return false;
  10.  
  11. return (checkBSTUtil(root.left, min, root.data - 1) && checkBSTUtil(root.right,root.data + 1, max));
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement