Build Binary Tree from Preorder and Inorder Traversal
Examples
Example 1:
Input: preorder = [1,2,3,4], inorder = [2,1,3,4]
Output: [1,2,3,null,null,null,4]
Example 2:
Input: preorder = [1], inorder = [1]
Output: [1]
Example 1:
Input: preorder = [1,2,3,4], inorder = [2,1,3,4]
Output: [1,2,3,null,null,null,4]
Example 2:
Input: preorder = [1], inorder = [1]
Output: [1]
You are given two integer arrays preorder and inorder.
preorder is the preorder traversal of a binary treeinorder is the inorder traversal of the same treeRebuild the binary tree from the preorder and inorder traversals and return its root.
1 <= inorder.length <= 1000inorder.length == preorder.length-1000 <= preorder[i], inorder[i] <= 1000