Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal
二叉树基本操作
[ ]O[ ]
[ ][ ]O
代码:
TreeNode *restore(vector<int> &inorder, vector<int> &postorder, int ip, int pp, int len) {
if (len == )
return NULL;
TreeNode *node = new TreeNode(postorder[pp + len - ]);
if (len == )
return node;
int leftLen = ;
while (inorder[ip + leftLen] != postorder[pp + len - ])
leftLen++;
node->left = restore(inorder, postorder, ip, pp, leftLen);
node->right = restore(inorder, postorder, ip + leftLen + , pp + leftLen, len - leftLen - );
return node;
}
TreeNode *buildTree(vector<int> &inorder, vector<int> &postorder) {
return restore(inorder, postorder, , , inorder.size());
}
Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal的更多相关文章
- Java for LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Total Accepted: 31041 Total Submissions: ...
- (二叉树 递归) 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 that ...
- [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 that ...
- 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 that ...
- C#解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 that ...
- LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树 C++
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- [leetcode] 106. Construct Binary Tree from Inorder and Postorder Traversal(medium)
原题地址 思路: 和leetcode105题差不多,这道题是给中序和后序,求出二叉树. 解法一: 思路和105题差不多,只是pos是从后往前遍历,生成树顺序也是先右后左. class Solution ...
- 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告
[LeetCode]106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告(Python) 标签: LeetCode ...
- 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
随机推荐
- c#获取多个List<class>合并、并将相同条件下的值累计sum
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- css3选择器——导图篇
css3选择器主要有:基本选择器 , 层次选择器, 伪类选择器 , 伪元素选择器 , 属性选择器 基本选择器 层次选择器 伪类选择器分为 动态伪类选择器, 目标伪类选择器, 语言伪类选择器, U ...
- Learning Scrapy笔记(零) - 前言
我已经使用了scrapy有半年之多,但是却一直都感觉没有入门,网上关于scrapy的文章简直少得可怜,而官网上的文档(http://doc.scrapy.org/en/1.0/index.html)对 ...
- Dapper多表查询(列名重复,类字段重复)映射方案
1. 一个主名,一个别名,设计时候属性和字段命名不同. 这样主名和别名都可以用的,在主名与别人重复时候用别名(别名可以设计的明确一点长一点,比如类名和字段结合) 2. 或者找一个字段多的直接继承出一个 ...
- Oracle Study Note : Users and Basic Security
1. view the default user account SQL> select username from dba_users; 2. lock all users and set t ...
- [转]从普通DLL中导出C++类 – dllexport和dllimport的使用方法(中英对照、附注解)
这几天写几个小程序练手,在准备将一个类导出时,发现还真不知道如果不用MFC的扩展DLL,是怎么导出的.但我知道dllexport可以导出函数和变量,而且MFC扩展DLL就算是使用了MFC的功能,但 ...
- 最大似然估计(MLE)和最大后验概率(MAP)
最大似然估计: 最大似然估计提供了一种给定观察数据来评估模型参数的方法,即:“模型已定,参数未知”.简单而言,假设我们要统计全国人口的身高,首先假设这个身高服从服从正态分布,但是该分布的均值与方差未知 ...
- hdu 2648 Shopping
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2648 纯暴力的方法T_T... 如下: #include<cstdio> #include ...
- 在windows上使用symfony创建简易的CMS系统(一)
http://blog.csdn.net/kunshan_shenbin/article/details/7164675 参考自:http://xsymfony.801.cxne.net/forum. ...
- 16位CPU多周期设计
16位CPU多周期设计 这个工程完成了16位CPU的多周期设计,模块化设计,有包含必要的分析说明. 多周期CPU结构图 多周期CPU设计真值表 对应某一指令的情况,但仅当对应周期时才为对应的输出,不是 ...