这题跟105. Construct Binary Tree from Preorder and Inorder Traversal是一个系列,代码抄袭了Construct Binary Tree from Inorder and Postorder Traversal,二叉树的算法应该说不难理解。
From the post-order array, we know that last element is the root. We can find the root in in-order array. Then we can identify the left and right sub-trees of the root from in-order array. Using the length of left sub-tree, we can identify left and right sub-trees in post-order array. Recursively, we can build up the tree.
Java
1 | /** |
Submission Detail
- 203 / 203 test cases passed.
- Runtime: 18 ms
- Your runtime beats 25.95 % of java submissions.