889. Construct Binary Tree from Preorder and Postorder Traversal
Medium
Given two integer arrays, preorder
and postorder
where preorder
is the preorder traversal of a binary tree of distinct values and postorder
is the postorder traversal of the same tree, reconstruct and return the binary tree.
If there exist multiple answers, you can return any of them.
Example 1:
Example 2:
Constraints:
1 <= preorder.length <= 30
1 <= preorder[i] <= preorder.length
All the values of
preorder
are unique.postorder.length == preorder.length
1 <= postorder[i] <= postorder.length
All the values of
postorder
are unique.It is guaranteed that
preorder
andpostorder
are the preorder traversal and postorder traversal of the same binary tree.
解題
Runtime: 0 ms, faster than 100%
Memory Usage: 3.3 MB, less than 69.57%
Last updated