#106

Construct Binary Tree from Inorder and Postorder Traversal

pupil · 580 · lc medium +29 · verified · 68.1% accepted · 8,671 likes · top 75%

play →

Description

You are given two integer arrays: inorder, the inorder traversal of a binary tree, and postorder, its postorder traversal. Use both sequences to rebuild and return the binary tree.

Example 1:

Input: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
Output: [3,9,20,null,null,15,7]

Example 2:

Input: inorder = [-1], postorder = [-1]
Output: [-1]

Code

1
2
3
4
5
6
7
8
9