Return the root node of a binary search tree that matches the given preorder traversal.
(Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.)
Note:
- 1 <= preorder.length <= 100
- The values of preorder are distinct.
給予一個前序遍歷,回傳對應的二元搜索樹的根節點。
(所謂的二元搜索樹是一種二元樹,其每一個節點的左子樹之值都小於自己,右子樹之值都大於自己。而所謂的前序遍歷是指從一棵樹的任一節點開始,先顯示它自己的值,再跑左子樹,最後跑右子樹。)
注意:
- 1 <= preorder.length <= 100
- 所有preorder的值都不同。
LeetCode
C++