320. Construct Binary Search Tree from Preorder Traversal

MediumBST

Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root. It is guaranteed that there is always possible to find a binary search tree with the given requirements for the given test cases.

Examples

Input: [8,5,1,7,10,12]

Output: [8,5,10,1,7,null,12]

Explanation: The unique BST with this preorder.

Constraints

  • 1 <= preorder.length <= 100
  • 1 <= preorder[i] <= 10^8
  • All the values of preorder are unique.
Loading...

Run checks all cases above. Submit evaluates all test cases.