Last updated
Was this helpful?
Last updated
Was this helpful?
https://leetcode.com/problems/validate-binary-search-tree
Given the root
of a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.
The right subtree of a node contains only nodes with keys greater than the node's key.
Both the left and right subtrees must also be binary search trees.
Example 1:
Example 2:
Constraints:
The number of nodes in the tree is in the range [1, 104]
.
-231 <= Node.val <= 231 - 1
BST, inorder traversal is transcendent.
Traversal: consider three part: left,right and itself, it's about order.
in this case, iteration is easier to understand.
First answer, so ugly, must be wrong.
becareful about the boudary, especially Integer.MAX_VALUE
Integer.MIN_VALUE
2/18/2018