You are viewing a single comment's thread. Return to all comments →
You can do it like this ( if u say this is clean :p)
boolean checkBST(Node root) { ArrayList<Integer> arr=new ArrayList<Integer>(); inorder(root,arr); int flag=0; for(int i=1;i<arr.size();i++) if(arr.get(i)>arr.get(i-1)) continue; else return false; return true; } void inorder(Node root,ArrayList<Integer> ar) { if(root==null)return; inorder(root.left,ar); ar.add(root.data); inorder(root.right,ar); }
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
You can do it like this ( if u say this is clean :p)