mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
30 lines
965 B
HTML
30 lines
965 B
HTML
<p>输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。</p>
|
||
|
||
<p>假设输入的前序遍历和中序遍历的结果中都不含重复的数字。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree.jpg" />
|
||
<pre>
|
||
<strong>Input:</strong> preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
|
||
<strong>Output:</strong> [3,9,20,null,null,15,7]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>Input:</strong> preorder = [-1], inorder = [-1]
|
||
<strong>Output:</strong> [-1]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>限制:</strong></p>
|
||
|
||
<p><code>0 <= 节点个数 <= 5000</code></p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>注意</strong>:本题与主站 105 题重复:<a href="https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/">https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/</a></p>
|