mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
32 lines
1.2 KiB
HTML
32 lines
1.2 KiB
HTML
<p>给定两个整数数组 <code>inorder</code> 和 <code>postorder</code> ,其中 <code>inorder</code> 是二叉树的中序遍历, <code>postorder</code> 是同一棵树的后序遍历,请你构造并返回这颗 <em>二叉树</em> 。</p>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree.jpg" />
|
|
<pre>
|
|
<b>输入:</b>inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
|
|
<b>输出:</b>[3,9,20,null,null,15,7]
|
|
</pre>
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
<pre>
|
|
<b>输入:</b>inorder = [-1], postorder = [-1]
|
|
<b>输出:</b>[-1]
|
|
</pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= inorder.length <= 3000</code></li>
|
|
<li><code>postorder.length == inorder.length</code></li>
|
|
<li><code>-3000 <= inorder[i], postorder[i] <= 3000</code></li>
|
|
<li><code>inorder</code> 和 <code>postorder</code> 都由 <strong>不同</strong> 的值组成</li>
|
|
<li><code>postorder</code> 中每一个值都在 <code>inorder</code> 中</li>
|
|
<li><code>inorder</code> <strong>保证</strong>是树的中序遍历</li>
|
|
<li><code>postorder</code> <strong>保证</strong>是树的后序遍历</li>
|
|
</ul>
|