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: ...
随机推荐
- django 数据库交互2
打开django shell python manage.py shell 输入命令 >>> from myapp import * >>> MySite.obje ...
- Sphinx 配置文件的说明【备忘】
## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python ...
- NOIp 2014 #5 解方程 Label:数论?
题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...
- Linux进程含义知多少
理想情况下,您应该明白在您的系统中运行的每一个进程.要获得所有进程的列表,可以执行命令 ps -ef(POSIX 风格)或 ps ax(BSD 风格).进程名有方括号的是内核级的进程,执行辅助功能(比 ...
- SDCycleScrollView 滚动视图的使用(广告)
github库链接https://github.com/gsdios/SDCycleScrollView 无限循环自动图片轮播器(一步设置即可使用) // 网络加载图片的轮播器 cycleScroll ...
- C#读取XML文件的方法
先写一个xml文件: <?xml version="1.0" encoding="utf-8" ?> <bookste> <!-- ...
- 关于C# winform中使用pictureBox显示大红叉的原因
pictureBox的关于image的属性有三 个,InitalImage,Image,ErrorImage分别表示picturebox的默认初始图片,当前可以设置的图片和出错之后默认显示的图 片,而 ...
- MySQL Command 常见命令
/* Load data from txt file */ LOAD DATA LOCAL INFILE "D:/data.txt" INTO TABLE tname; /* Lo ...
- Java 中的转义字符
注意斜杠方向,为键盘右上角的斜杠 \t 在当前编辑位置插入一个 tab \b 在当前编辑位置插入一个空格 \n 换行(在当前编辑位置插入 a newline) \r 在当前编辑位置插入一个回车 ...
- ArcGIS AddIN开发异常之--“ValidateAddInXMLTask”任务意外失败
ArcGIS AddIN开发时,产生如下异常错误 2 “ValidateAddInXMLTask”任务意外失败.System.NullReferenceException: 未将对象引用设置到对象的 ...