Nav: << previous: 105.从前序与中序遍历序列构造二叉树 | next: 107.二叉树的层序遍历 II >>
Description
tab: English
<p>Given two integer arrays <code>inorder</code> and <code>postorder</code> where <code>inorder</code> is the inorder traversal of a binary tree and <code>postorder</code> is the postorder traversal of the same tree, construct and return <em>the binary tree</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/tree.jpg" style="width: 277px; height: 302px;" />
<pre>
<strong>Input:</strong> inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]
<strong>Output:</strong> [3,9,20,null,null,15,7]
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> inorder = [-1], postorder = [-1]
<strong>Output:</strong> [-1]
</pre>
<p> </p>
<p><strong>Constraints:</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> and <code>postorder</code> consist of <strong>unique</strong> values.</li>
<li>Each value of <code>postorder</code> also appears in <code>inorder</code>.</li>
<li><code>inorder</code> is <strong>guaranteed</strong> to be the inorder traversal of the tree.</li>
<li><code>postorder</code> is <strong>guaranteed</strong> to be the postorder traversal of the tree.</li>
</ul>
---
[submissions](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/submissions/) | [solutions](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/solutions/)
tab: 中文
<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>
---
[提交记录](https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/submissions/) | [题解](https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122