1. /**
  2. * Definition for a binary tree node.
  3. * struct TreeNode {
  4. * int val;
  5. * struct TreeNode *left;
  6. * struct TreeNode *right;
  7. * };
  8. */
  9. struct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize) {
  10. struct TreeNode *root;
  11. int index=0;
  12. if(inorderSize<=0)return NULL;
  13. root=(struct TreeNode*)malloc(sizeof(struct TreeNode));
  14. //root->left=root->right=NULL;
  15. root->val=postorder[postorderSize-1];
  16. while(inorder[index]!=root->val)index++;
  17. root->left=buildTree(inorder,index,postorder,index);
  18. root->right=buildTree(inorder+index+1,inorderSize-index-1,postorder+index,postorderSize-index-1);
  19. return root;
  20. }

  

  

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. django 数据库交互2

    打开django shell python manage.py shell 输入命令 >>> from myapp import * >>> MySite.obje ...

  2. Sphinx 配置文件的说明【备忘】

    ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python ...

  3. NOIp 2014 #5 解方程 Label:数论?

    题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .i ...

  4. Linux进程含义知多少

    理想情况下,您应该明白在您的系统中运行的每一个进程.要获得所有进程的列表,可以执行命令 ps -ef(POSIX 风格)或 ps ax(BSD 风格).进程名有方括号的是内核级的进程,执行辅助功能(比 ...

  5. SDCycleScrollView 滚动视图的使用(广告)

    github库链接https://github.com/gsdios/SDCycleScrollView 无限循环自动图片轮播器(一步设置即可使用) // 网络加载图片的轮播器 cycleScroll ...

  6. C#读取XML文件的方法

    先写一个xml文件: <?xml version="1.0" encoding="utf-8" ?> <bookste> <!-- ...

  7. 关于C# winform中使用pictureBox显示大红叉的原因

    pictureBox的关于image的属性有三 个,InitalImage,Image,ErrorImage分别表示picturebox的默认初始图片,当前可以设置的图片和出错之后默认显示的图 片,而 ...

  8. MySQL Command 常见命令

    /* Load data from txt file */ LOAD DATA LOCAL INFILE "D:/data.txt" INTO TABLE tname; /* Lo ...

  9. Java 中的转义字符

    注意斜杠方向,为键盘右上角的斜杠 \t 在当前编辑位置插入一个 tab \b 在当前编辑位置插入一个空格 \n 换行(在当前编辑位置插入 a newline) \r 在当前编辑位置插入一个回车     ...

  10. ArcGIS AddIN开发异常之--“ValidateAddInXMLTask”任务意外失败

     ArcGIS AddIN开发时,产生如下异常错误 2 “ValidateAddInXMLTask”任务意外失败.System.NullReferenceException: 未将对象引用设置到对象的 ...