- Difficulty: Medium
- Tags: LeetCode, Medium, Stack, Tree, Binary Search Tree, Recursion, Array, Binary Tree, Monotonic Stack, leetcode-255, O(n), O(1), 🔒
Problem
Given an array of unique integers preorder
, return true
if it is the correct preorder traversal sequence of a binary search tree.
Â
Example 1:
Input: preorder = [5,2,1,3,6] Output: true
Example 2:
Input: preorder = [5,2,6,1,3] Output: false
Â
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?