递归思想,找到根节点,问题便分解为左子树与右子树
leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode buildTree(int[] inorder, int[] postorder) {
int size = inorder.length;
if(size==0) return null;
return buildTreefromin_post(inorder, 0, size-1, postorder, 0, size-1);
}
private TreeNode buildTreefromin_post(int[] inorder, int l_in, int r_in,
int[] postorder, int l_p, int r_p){
TreeNode root = new TreeNode(0)