You are viewing a single comment's thread. Return to all comments →
Slightly shorter but otherwise the same:
boolean checkBST(Node root) { return checkBSTRecur(root, Long.MIN_VALUE, Long.MAX_VALUE); } boolean checkBSTRecur( Node curNode, long lowerBound, long upperBound){ return curNode == null || (lowerBound < curNode.data && curNode.data < upperBound && checkBSTRecur(curNode.left, lowerBound, curNode.data) && checkBSTRecur(curNode.right, curNode.data, upperBound)); }
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 →
Slightly shorter but otherwise the same: