You are viewing a single comment's thread. Return to all comments →
Easy approach with recursion:
boolean checkBST(Node root) { return checkBST(root, Integer.MIN_VALUE, Integer.MAX_VALUE); } boolean checkBST(Node root, int min, int max) { if (root == null) return true; if (root.data <= min || root.data >= max) return false; if (!checkBST(root.left, min, root.data) || !checkBST(root.right, root.data, max)) return false; return true; }
Seems like cookies are disabled on this browser, please enable them to open this website
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Easy approach with recursion: