Given the root of a binary tree, decide whether it is a valid binary search tree (BST).
In a valid BST, a node's left subtree contains only values strictly less than the node's value, its right subtree contains only values strictly greater, and both subtrees are valid BSTs themselves.
Examples
Example 1
- Input
- root = [2, 1, 3]
- Output
- true
Example 2
- Input
- root = [5, 1, 4, null, null, 3, 6]
- Output
- false
- Why
- The root is 5, but its right child 4 is smaller than 5.
Constraints
- The tree has between
1and10^4nodes. -2^31 <= Node.val <= 2^31 - 1