/**
* 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的更多相关文章

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

    Given inorder and postorder traversal of a tree, construct the binary tree. 题目大意:给定一个二叉树的中序和后续序列,构建出 ...

  2. 【题解二连发】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 ...

  3. Construct Binary Tree from Inorder and Postorder Traversal

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

  4. 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 ...

  5. 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 ...

  6. LeetCode: Construct Binary Tree from Inorder and Postorder Traversal 解题报告

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

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

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

  8. [Leetcode Week14]Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/pr ...

  9. 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: ...

随机推荐

  1. UVa1515 Pool construction(最小割)

    题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. 相遇点对 & 数点问题

    题意: 一个长为l的环,环上有n个点,每个点以一定的速度顺时针或逆时针运动,两个点相遇即某一时刻内两个点位置相同. 求有多少点对相遇----相同点对出现多次仅统计一次. SOL: 考试的时候想到用线段 ...

  3. jquery.cookie.js使用

    1.下载jquery.cookie.js 官网:http://plugins.jquery.com/cookie/ 或 http://pan.baidu.com/s/1mgynA8g 2.使用方法 $ ...

  4. Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

    本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个 ...

  5. 洛谷 P1038 神经网络 Label:拓扑排序 && 坑 60分待查

    题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷款风险评估等诸多领域有广泛的应用.对神经网络的研究一直是当今 ...

  6. 【BZOJ】1124: [POI2008]枪战Maf

    题意 \(n(n < 1000000)\)个人,每个人\(i\)指向一个人\(p_i\),如果轮到\(i\)了且他没死,则他会将\(p_i\)打死.求一种顺序,问死的人最少和最多的数目. 分析 ...

  7. 【HDU】3506 Monkey Party

    http://acm.hdu.edu.cn/showproblem.php?pid=3506 题意:环形石子合并取最小值= =(n<=1000) #include <cstdio> ...

  8. Java_过滤字符串中非汉子的内容

    /** * 去除“第”之前的所有非汉字内容 */ private String clearNotChinese(String buff){ String tmpString =buff.replace ...

  9. 20145330《Java程序设计》第三周学习总结

    20145330 <Java程序设计>第三周学习总结 第三周知识的难度已经逐步上升,并且一周学习两章学习压力也逐渐加大,需要更高效率的来完成学习内容,合理安排时间. 类与对象 对象(Obj ...

  10. python 面向对象 初级

    面向对象 与 面向过程 面向对象对象,是根据某个对象,进行编写对象属性,不考虑对象以外的因素,只对对象本事的一些属于自己的属性进行创造,不用考虑 业务之间的逻辑. 面向过程, 是按照业务的一步步发展进 ...