###### Construct Binary Tree from Inorder and Postorder Traversal

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

Construct Binary Tree from Preorder and Inorder Traversal思路基本一致，主要是根据在中序遍历中找到当前的值，然后通过对应关系递归。

/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
return creatTree(0, inorder.size() - 1, 0, postorder.size() - 1, inorder, postorder);
}
TreeNode*creatTree(int in_begin, int in_end, int post_begin,int post_end, vector<int> &inorder, vector<int> &postorder){
if(post_begin > post_end)    return NULL;
TreeNode* root = new TreeNode(postorder[post_end]);
int index = 0;
for(int i = in_end; i >= 0; --i){
if(inorder[i] == root -> val){
index = i;
break;
}
}
root -> right = creatTree(index + 1, in_end, post_begin + index - in_begin, post_end - 1, inorder, postorder);
root -> left = creatTree(in_begin, index - 1, post_begin, post_begin + index - in_begin - 1, inorder, postorder);
return root;
}
};

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

2015-08-09 06:39:31

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

2014-04-24 09:02:17

#### 106 Construct Binary Tree from Inorder and Postorder Traversal

2015-12-09 20:29:35

#### LeetCode Construct Binary Tree from Inorder and Postorder Traversal 思考分析过程分享

2013-11-12 13:20:50

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

2014-12-04 23:07:11

#### LeetCode(106)Construct Binary Tree from Inorder and Postorder Traversal

2014-01-15 06:20:17

#### 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 解题报告

2016-06-01 23:42:08

#### LeetCode: Construct Binary Tree from Inorder and Postorder Traversal [106]

2014-06-03 08:23:27

#### LeetCode 106：Construct Binary Tree from Postorder and Inorder Traversal

2015-06-01 19:09:42

## 不良信息举报

Construct Binary Tree from Inorder and Postorder Traversal