← 返回 bytedance 的题目列表Construct Binary Tree from Preorder and Inorder Traversal
类型:online_judge
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
Example:
Input: preorder = [3,9,20,15,7] inorder = [9,3,15,20,7]
Output: Return the root of the constructed tree.
Constraints:
1 <= preorder.length <= 3000
inorder.length == preorder.length
-3000 <= preorder[i], inorder[i] <= 3000
preorder and inorder contain no duplicate elements
inorder will have unique elements
Example
Input
3,9,20,15,7
9,3,15,20,7
Output
TreeNode object representing the tree structure