106 Construct Binary Tree form Inorder and Postorder Traversal
Previous105 Construct Binary Tree from Preorder and Inorder TraversalNext652 Find Duplicate Subtrees
Last updated
Was this helpful?
Last updated
Was this helpful?
Given inorder and postorder traversal of a tree, construct the binary tree.
Note: You may assume that duplicates do not exist in the tree.
这题跟很像,一看,这不就是倒着来嘛。我还是一如既往地懒,用global index来解决了。这里因为是postorder,所以要注意index从n-1开始一直减少到0.然后构建树时记得倒着来。这里同样每次用O(n)找断开位置,同样可以用hashmap优化。