Construct Binary Tree from Inorder and Postorder Traversal || LeetCode
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize) {
struct TreeNode *root;
int index=0;
if(inorderSize<=0)return NULL;
root=(struct TreeNode*)malloc(sizeof(struct TreeNode));
//root->left=root->right=NULL;
root->val=postorder[postorderSize-1];
while(inorder[index]!=root->val)index++;
root->left=buildTree(inorder,index,postorder,index);
root->right=buildTree(inorder+index+1,inorderSize-index-1,postorder+index,postorderSize-index-1);
return root;
}
Construct Binary Tree from Inorder and Postorder Traversal || LeetCode的更多相关文章
- Construct Binary Tree from Inorder and Postorder Traversal——LeetCode
Given inorder and postorder traversal of a tree, construct the binary tree. 题目大意:给定一个二叉树的中序和后续序列,构建出 ...
- 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal
LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...
- Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
- 36. Construct Binary Tree from Inorder and Postorder Traversal && Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal OJ: https://oj.leetcode.com/problems/cons ...
- LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal
LeetCode:Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder trav ...
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal 解题报告
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
- 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
- [Leetcode Week14]Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/pr ...
- 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: ...
随机推荐
- HDU5816 Hearthstone(状压DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collec ...
- .net平台下垃圾回收机制
引言:使用c++进行编程,内存的处理绝对是让每个程序设计者最头疼的一块了.但是对于.net平台下使用c#语言开发系统,内存管理可以说已经不算是问题了.在.net平台下CLR负责管理内存,CLR中的垃圾 ...
- java 程序中添加socks 5代理
在需要使用代理的地方添加如下code: System.getProperties().put("socksProxySet","true"); System.g ...
- java.io包详细解说
转自:http://hzxdark.iteye.com/blog/40133 hzxdark的博客 我不知道各位是师弟师妹们学java时是怎样的,就我的刚学java时的感觉,java.io包是最让我感 ...
- float的元素脱离文档流,但不完全脱离,只是提升了半层;
float的元素脱离文档流,但不完全脱离,只是提升了半层:
- URAL 1152. False Mirrors(DP)
题目链接 理解了题意之后,就不难了..状态压缩+暴力. #include <cstring> #include <cstdio> #include <string> ...
- JsonP的简单demo
服务器端代码 public ActionResult GetNewUploadCourseIds() { "; var result = new Result<NewUpload> ...
- 如何在osg中删除EventHandler
最近在一个项目中需要动态的添加和删除EventHandler,添加的时候很顺利,使用view->addEventHandler()函数就可以了. 不过在删除的时候,出现点麻烦. 直接调用vi ...
- iOS 上线被拒收集
根据上线被拒的原因 自己 也在慢慢总结 希望对各位有所帮助 1)QQ 微信 等第三方平台 必须要做是否安装应用的检测
- 配置Nginx支持ThinkPHP的URL重写和PATHINFO
ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可.在Apache下只需要开启mod_rew ...