Is This a Binary Search Tree?

  • + 0 comments

    Was able to solve it because of your comment. thanks a lot. Here's my code.

    static ArrayList<Integer> list = new ArrayList<Integer>();
        boolean checkBST(Node root) {
            
            inOrder(root);
            
            for(int i = 1; i< list.size(); i++){
                if(list.get(i)<=list.get(i-1))
                    return false;
            }
            return true;
             
        }
        
        void inOrder(Node root){
            if(root == null)
                return;
            inOrder(root.left);
            list.add(root.data);
            inOrder(root.right);
        }