mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
36 lines
1.4 KiB
HTML
36 lines
1.4 KiB
HTML
<p>给定两个整数数组,<code>preorder</code> 和 <code>postorder</code> ,其中 <code>preorder</code> 是一个具有 <strong>无重复</strong> 值的二叉树的前序遍历,<code>postorder</code> 是同一棵树的后序遍历,重构并返回二叉树。</p>
|
||
|
||
<p>如果存在多个答案,您可以返回其中 <strong>任何</strong> 一个。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><img src="https://assets.leetcode.com/uploads/2021/07/24/lc-prepost.jpg" style="height: 265px; width: 304px;" /></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]
|
||
<strong>输出:</strong>[1,2,3,4,5,6,7]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong> preorder = [1], postorder = [1]
|
||
<strong>输出:</strong> [1]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= preorder.length <= 30</code></li>
|
||
<li><code>1 <= preorder[i] <= preorder.length</code></li>
|
||
<li><code>preorder</code> 中所有值都 <strong>不同</strong></li>
|
||
<li><code>postorder.length == preorder.length</code></li>
|
||
<li><code>1 <= postorder[i] <= postorder.length</code></li>
|
||
<li><code>postorder</code> 中所有值都 <strong>不同</strong></li>
|
||
<li>保证 <code>preorder</code> 和 <code>postorder</code> 是同一棵二叉树的前序遍历和后序遍历</li>
|
||
</ul>
|