#106

Construct Binary Tree from Inorder and Postorder Traversal

medium · verified · 68.1% accepted · 8,671 likes · top 75%

array · hash table · divide and conquer · tree · binary tree

⊣ practice⊣ quiz⊣ open on leetcode ↗

Description

Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct 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]

Solution