Two arrays describe the same binary tree.
preorder lists the nodes by visiting the root first, then the left subtree, then the right subtree.
inorder lists the nodes by visiting the left subtree first, then the root, then the right subtree.
All values are different. Rebuild the tree and return it.
How the judge passes the data
Examples
Example 1:
Input: preorder = [1,2,4,5,3], inorder = [4,2,5,1,3]
Output: [1,2,3,4,5]
Explanation: The root is 1. The values 4, 2, 5 are on its left and 3 is on its right.
Example 2:
Input: preorder = [8,6,7], inorder = [6,7,8]
Output: [8,6,null,null,7]
Explanation: The root is 8. The values 6 and 7 are on its left. In that part, 6 is the root and 7 is its right child.
Example 3:
Input: preorder = [9], inorder = [9]
Output: [9]
Explanation: One node only.