Suppose we have the following code with a data structure, TreeNode
, and a method, isValidBST
.
Definition: A given binary tree T is a valid Binary Search Tree (BST) if and only if:
- The left subtree contains only values strictly less than the value in the root node.
- The right subtree contains only values strictly greater than the value in the root node.
- All subtrees are valid BSTs.