Given inorder and postorder traversal arrays of a binary tree, construct the original tree and return its root as a level-order array. Pattern focus: Construct Tree from Traversals. The postorder array identifies the root, and inorder splits the tree into left and right parts.
inorder = inorder traversal, postorder = postorder traversal
level-order array representation of the reconstructed tree
Example 1:
Input:
inorder = [9,3,15,20,7] postorder = [9,15,7,20,3]
Output:
[3,9,20,null,null,15,7]
Explanation:
This is the classic reconstruction example.
Example 2:
Input:
inorder = [2,1] postorder = [2,1]
Output:
[1,2]
Explanation:
The last postorder value is the root.