Given arrays
preorder and inorder — tree traversals. Reconstruct the binary tree and return its root.Example 1
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
Output: [3,9,20,null,null,15,7]
Explanation: The root is the first element of preorder.
Output: [3,9,20,null,null,15,7]
Explanation: The root is the first element of preorder.
Example 2
Input: preorder = [-1], inorder = [-1]
Output: [-1]
Explanation: A tree with one node.
Output: [-1]
Explanation: A tree with one node.