We’re preparing your current view and syncing the latest data.
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.
Inorder traversal means traversing the tree in the left-root-right order. Postorder traversal means traversing the tree in the left-right-root order.
You may assume that duplicates do not exist in the tree.
Two integer arrays: inorder and postorder representing the inorder and postorder traversal of a binary tree.
Return the root node of the constructed binary tree.
1 <= inorder.length <= 3000 postorder.length == inorder.length -3000 <= inorder[i], postorder[i] <= 3000 inorder and postorder consist of unique values. Each value of postorder also appears in inorder.
Example 1
Input
inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
Output
[3,9,20,null,null,15,7]
Explanation
The binary tree constructed has 3 as root with left child 9 and right subtree rooted at 20 with children 15 and 7.