0255. Verify Preorder Sequence in Binary Search Tree
Last updated
Last updated
https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree
Given an array of unique integers preorder
, return true
if it is the correct preorder traversal sequence of a binary search tree.
Example 1:
Example 2:
Constraints:
1 <= preorder.length <= 104
1 <= preorder[i] <= 104
All the elements of preorder
are unique.
Follow up: Could you do it using only constant space complexity?
essential idea: right sub-tree always > parent node. very hard to come up with that.
Key point: using array like a stack.