You are viewing a single comment's thread. Return to all comments →
Here my my solution. Could pass only 4 test cases.
boolean checkBST(Node root) { if(root==null){ return false; } else if(root.left==null && root.right==null){ return true; } return checkBSTHelper(root); } boolean checkBSTHelper(Node root) { while (true) { if (root.left != null) { if (root.left.data < root.data) { checkBSTHelper(root.left); } else { return false; } } else if (root.right != null) { if (root.right.data > root.data) { checkBSTHelper(root.right); } else { return false; } } return true; } }
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 →
Here my my solution. Could pass only 4 test cases.