Problem · Tree
Validate Binary Search Tree
Learn this problemProblem statement
Return whether the binary tree is a valid binary search tree. Every value in a left subtree must be strictly smaller than its ancestor, and every value in a right subtree must be strictly larger.
Function
isValidBST(root: TreeNode) → booleanExamples
Example 1
root = [2,1,3]return = trueBoth children satisfy the strict bounds imposed by the root.
Constraints
- The tree contains between
1and10000nodes. - Node values fit in a signed 32-bit integer.