[LeetCode] 889. Construct Binary Tree from Preorder and Postorder Traversal 由先序和后序遍历建立二叉树
Posted grandyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] 889. Construct Binary Tree from Preorder and Postorder Traversal 由先序和后序遍历建立二叉树相关的知识,希望对你有一定的参考价值。
Return any binary tree that matches the given preorder and postorder traversals.
Values in the traversals?pre
?and?post
?are distinct?positive integers.
Example 1:
Input: pre = [1,2,4,5,3,6,7], post = [4,5,2,6,7,3,1]
Output: [1,2,3,4,5,6,7]
Note:
1 <= pre.length == post.length <= 30
pre[]
?and?post[]
?are both permutations of?1, 2, ..., pre.length
.- It is guaranteed an answer exists. If there exists multiple answers, you can return any of them.
类似题目:
Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal
参考资料:
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/
LeetCode All in One 题目讲解汇总(持续更新中...)
以上是关于[LeetCode] 889. Construct Binary Tree from Preorder and Postorder Traversal 由先序和后序遍历建立二叉树的主要内容,如果未能解决你的问题,请参考以下文章
889.Construct Binary Tree from Preorder and Postorder Traversal
889. Construct Binary Tree from Preorder and Postorder Traversal - Medium