Given inorder and postorder traversal of a tree, construct the binary tree.

Note:
You may assume that duplicates do not exist in the tree.

Subscribe to see which companies asked this question

/**
 * 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) {
    int i;
    struct TreeNode *Node;

     >= inorderSize){
        return NULL;
    }
    ; i < inorderSize; i++){
        ]){
            break;
        }
    }
    Node = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    Node->val = postorder[postorderSize - ];
    Node->left = buildTree(inorder, i, postorder, i);
    Node->right = buildTree(inorder + i + , inorderSize - i - , postorder + i, postorderSize - i - );
    return Node;
}

LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal的更多相关文章

  1. 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告

    [LeetCode]106. Construct Binary Tree from Inorder and Postorder Traversal 解题报告(Python) 标签: LeetCode ...

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

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

  3. LeetCode OJ: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 ...

  4. 【LeetCode OJ】Construct Binary Tree from Inorder and Postorder Traversal

    Problem Link: https://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-trav ...

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

  6. 【一天一道LeetCode】#106. Construct Binary Tree from Inorder and Postorder Traversall

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...

  7. 【LeetCode】105 & 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 ...

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

  9. (二叉树 递归) 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 ...

随机推荐

  1. C# 6.0 特性

    C#6.0主要提供了一些语法糖,另外还提供了新的编译器Roslyn地址https://github.com/dotnet/roslyn 一下列举几个新增的语法糖: 1.构造一个类: public cl ...

  2. UML Sequence sample: if-else

    if (balance >= amount) { ... } else { ... }

  3. linux下RDP客户端及服务器

    tsclient redsktop remmina   -->对ubuntu支持的非常不错 XRdp 集合vnc作为rdp服务器端使用;

  4. MFC自绘控件不错的网站收集,不定时更新。

    找资料的时候,遇到好的网站收集起来,当时看看就忘记网址,下次再找又找不到,写下来才记得牢.欢迎大家留言,共同收集. 国外的: 1.codeproject https://www.codeproject ...

  5. 脚本工具: 查看当前系统被写入的FD

    #!/bin/bash touch /tmp/sn2 /tmp/sn4 /tmp/sn6 /tmp/sn3 redir=/dev/null which lsof >&/dev/null ...

  6. php工作笔记7-概率算法

    a/m  b/m   c/m   d/m   10%    40%    20% a+b+c+d+... < = m array k   =  {a,b,c...} randt = rand(1 ...

  7. Foundation ----->NSNumber

    /*--------------------NSNumber--------------------*/     //包装基本数据类型          //1.创建number对象     //12 ...

  8. 命令与文件的查询 which whereis locate find

    一:which which查找脚本文件也就是我们的系统命令 用法:which [command] 默认根据我们PATH路径去查找,但是不同的用户肯定设置不同的PATH,所以就像普通用户查找不到一些/s ...

  9. 通过innobackupex实现对MySQL的增量备份与还原

    备份 增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --password=test /backup/ 备注:test是我的MySQL服务的root用户的密码,/b ...

  10. python基础学习笔记3

    特殊方法与多范式   Python一切皆对象,但同时,Python还是一个多范式语言(multi-paradigm),你不仅可以使用面向对象的方式来编写程序,还可以用面向过程的方式来编写相同功能的程序 ...