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 ...
随机推荐
- firefox 中碰到的一个小坑
情况描述: 在一个处于正常文档流的div中,里面有一部分文字,还有个有浮动的块, 上代码 HTML: <div class="container"> this is ...
- pm2 开机自启动如何弄?
1.使用pm2启动node :# pm2 start /home/wwwroot/web.js --watch 2.dump这些进程列表:# pm2 save 3.生成自启动脚本:# pm2 star ...
- redis 入门
1.命令行工具 在windows上巧命令行指令,实在是令人痛苦,本人实在是受不了windows下cmd的笨,powershell的蠢,只能换一个了. 介绍一款cmd工具cmder(github上开源) ...
- IBM开发者 JSON 教程
在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.掌握 Ajax 的这一期讨论另一种有用的数据格式 JavaScript Object Notation(JSON),以及如何 ...
- 多线程基本概论multithread
多线程 基本概念 进程 进程是指在系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内 通过 活动监视器 可以查看 Mac 系统中所开启的进程 线程 进程要想 ...
- windows下找不到strings.h
头文件用的strings.h,换成string.h就好了.但是以前的Linux系统下用strings.h,strerror都能正常编译,怎么样能正常使用strings.h linux系统下的库问题跟w ...
- 实习感悟——SQL语句
在这次实习中用到了很多SQL语句,下面就给大家分享分享: 1.group by 字面意思我们一看就知道groupby通过分组的意思,通过数据库某个字段的分组我们可以做什么?联系到生活中,我们给一组对象 ...
- Windows Phone中使用Native Code
前言 Windows Phone 8 SDK中一个非常有用的特性,就是可以通过Windows Phone Runtime Component (WinPRT)使用C++代码来处理运算量大的任 ...
- go again
Introducation (1)How to organize go code (2)How to develope go package (3)How to use go tool How to ...
- Go append方法
append用来将元素添加到切片末尾并返回结果.看代码: package main import "fmt" func main() { x := [],,} y := [],,} ...