题目

Given inorder and postorder traversal of a tree, construct the binary tree.

Note:
You may assume that duplicates do not exist in the tree.

For example, given

inorder = [9,3,15,20,7]
postorder = [9,15,7,20,3]
Return the following binary tree:

    3/ \9  20/  \15   7

解题思路

跟LeetCode: 105. Construct Binary Tree from Preorder and Inorder Traversal一模一样的解法,只是把前序数组的每次输出第一个换成后序数组输出最后一个。此外,105是先左节点再右节点,106反过来。

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = Noneclass Solution:def buildTree(self, inorder: List[int], postorder: List[int]) -> TreeNode:
#         while postorder:
#             print(postorder.pop())if inorder:root_val = postorder.pop()# print(inorder.index(root_val))ind = inorder.index(root_val)root = TreeNode(root_val)root.right = self.buildTree(inorder[ind+1:], postorder)root.left = self.buildTree(inorder[0:ind], postorder)return root

LeetCode: 106. Construct Binary Tree from Inorder and Postorder Traversal相关推荐

  1. LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal

    LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal Solution1:我的答案 仿照105题写的答案 / ...

  2. LeetCode - 106 - Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  3. leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal | 106. 从中序后序遍历序列构造二叉树(Java)

    题目 https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题解 待优化: ...

  4. 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  5. leetcode -day23 Construct Binary Tree from Inorder and Postorder Traversal Construct Binary Tree f

    1.  Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder travers ...

  6. LeetCode 889. Construct Binary Tree from Preorder and Postorder Traversal

    原题链接在这里:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/ 题 ...

  7. leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  8. LeetCode Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  9. Construct Binary Tree from Inorder and Postorder Traversal

    题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume ...

最新文章

  1. MindSpore基本原理
  2. Xamarin Essentials教程获取路径文件系统FileSystem
  3. IntelliJ IDEA 2020.2.4款 神级超级牛逼插件推荐(自用,真的超级牛逼)
  4. 13.SpringMVC和Spring集成(一) 14.SpringMVC和Spring集成(二)
  5. BOOST_VMD_ASSERT宏相关的测试程序
  6. boost::shared_mutex相关的测试程序
  7. oracle客户端没有deinstall.bat,Oracle数据库11gR2的卸载 - deinstall
  8. [转]C++的坑真的多吗?
  9. 获取数据 - 下载附件解压附件 - Python代码
  10. python地图标注_Python 给定的经纬度标注在地图上的实现方法
  11. IP路由故障关于BGP的疑问解答
  12. mysql5.7存储过程实例_MySQL 存储过程简单实例
  13. 将一个项目中的图片存到另一个项目中_复盘一个Smart200小项目(2)
  14. 获取本地ip(一个或多个都能取)
  15. ArcGIS_重分类
  16. windows设置开机自动启动程序
  17. 新手选择蓝牙耳机要注意什么?双11发烧友疯狂推荐五款蓝牙耳机
  18. 【转】为什么要使用ModelDriven
  19. 为什么面试要问hashmap 的原理
  20. 微信开发者工具:代码更新后页面未刷新

热门文章

  1. 对ajax回调函数的研究
  2. 基于lvs(DR模式)的keepalived部署
  3. CentOS 7 安装jdk
  4. HTML DOM getElementById() 方法
  5. Android ORMLite 框架的入门用法
  6. [生活化技术]组合模式 vs. 理发店价格表
  7. mysql是如何管理数据_【MySQL】如何管理数据库
  8. python读取浮点数与源文件不同
  9. 数据处理之不平衡数据过采样与下采样
  10. linux安装python3命令-linux系统下安装python3及其配置