Validate a Strict Binary Search Tree
Problem statement
Determine whether a binary tree is a binary search tree.
For this exercise, assume a strict BST: every value in a node's entire left subtree is smaller than that node's value, and every value in its entire right subtree is larger. Equal values are not allowed. An empty tree is valid.
Function
isStrictBST(root: TreeNode) → booleanExamples
Example 1
root = [2,1,3]return = trueAll left-subtree values are smaller and all right-subtree values are larger.
Example 2
root = [5,1,4,null,null,3,6]return = falseThe right subtree contains 4 and 3, which violate the root bound 5.
Example 3
root = []return = trueFor this exercise, the empty tree is valid.
Constraints
- For this exercise, assume a finite acyclic binary tree containing
0through500nodes. -10^9 <= node.val <= 10^9.