TEXT   83
check BST
Guest on 12th May 2022 06:41:09 PM


  1. public boolean checkBST(Node root) {
  2.        
  3.         return isBST(root,Integer.MIN_VALUE,Integer.MAX_VALUE);
  4.     }
  5.  
  6.     public boolean isBST(Node root,int a,int b) {
  7.        
  8.         if(root == null) return true;
  9.        
  10.         if( ((root.data > a) && (root.data<b)) && (isBST(root.left,a,root.data)) && (isBST(root.right,root.data,b)) ) {
  11.             return true;
  12.         }
  13.         return false;
  14.     }

Raw Paste

Login or Register to edit or fork this paste. It's free.