Description
Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as: The left subtree contains only nodes with keys less than the node's key. The right subtree contains only nodes with keys greater than the node's key. Both subtrees must also be valid BSTs.
Examples
Input:
root = [2,1,3]Output:
trueExplanation:
Valid BST: 1 < 2 < 3
Input:
root = [5,1,4,null,null,3,6]Output:
falseExplanation:
The root's right child is 4 which is less than 5.
Input:
root = [1]Output:
trueExplanation:
A single-node tree is always a valid BST since there are no children to violate the BST property.
Constraints
- •
The number of nodes in the tree is in the range [1, 10⁴] - •
-2³¹ ≤ Node.val ≤ 2³¹ - 1