Problem
1 | Given a binary tree, determine if it is a valid binary search tree (BST). |
Solution
Sol 1 recusive
Acording to rule of BST, the current node must be larger than its left child and all of its offspring.
we can to pass the upper and lower boundary into a recursive function
1 | # Definition for a binary tree node. |
Sol 2
traverse the tree by inorder traverse, and check if the order is sorted.
1 | # Definition for a binary tree node. |