###### Middle-题目71：105. Construct Binary Tree from Preorder and Inorder Traversal

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

struct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int inorderSize) {
if(preorderSize == 0 && inorderSize == 0)
return NULL;
else {
int middle = preorder[0];
int i;
for (i = 0;inorder[i] != middle; i++);
struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode)); //generate root
root->val = middle;
root->left = buildTree(preorder+1, i, inorder, i);
root->right = buildTree(preorder+i+1, preorderSize-i-1, inorder+i+1, inorderSize-i-1);
return root;
}
}

20ms,beats 23.68%,众数20ms,36.84%
Cmershen的碎碎念：

#### 【LeetCode】105. Construct Binary Tree from Preorder and Inorder Traversal 解题报告

2016-06-01 23:42:08

#### Construct Binary Tree from Preorder and Inorder Traversal -- LeetCode

2014-04-24 08:43:09

#### LeetCode 105：Construct Binary Tree from Preorder and Inorder Traversal

2015-05-20 23:09:41

#### 【LeetCode-面试算法经典-Java实现】【105-Construct Binary Tree from Preorder and Inorder Traversal（构造二叉树）】

2015-08-09 06:37:17

#### [LeetCode-21]Construct Binary Tree from Preorder and Inorder Traversal

2014-05-21 05:59:08

#### C++详解Leetcode:105. Construct Binary Tree from Preorder and Inorder Traversal

2017-07-30 17:34:05

#### 【LeetCode-面试算法经典-Java实现】【106-Construct Binary Tree from Inorder and Postorder Traversal（构造二叉树II）】

2015-08-09 06:39:31

#### leetcode笔记：Construct Binary Tree from Preorder and Inorder Traversal

2015-11-30 23:54:21

#### LeetCode(105) Construct Binary Tree from Preorder and Inorder Traversal解题报告

2015-12-12 22:39:59

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

2014-12-04 23:07:11

## 不良信息举报

Middle-题目71：105. Construct Binary Tree from Preorder and Inorder Traversal