import java.util.Arrays;
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public TreeNode
reConstructBinaryTree(
int [] pre,
int [] in) {
if((pre.length<=
0) || (in.length<=
0))
return null;
TreeNode root =
new TreeNode(pre[
0]);
int index;
for(index=
0;index<in.length;index++)
{
if(in[index]==pre[
0])
break;
}
root.left = reConstructBinaryTree(Arrays.copyOfRange(pre,
1,index+
1),Arrays.copyOfRange(in,
0,index));
root.right = reConstructBinaryTree(Arrays.copyOfRange(pre,index+
1,in.length),Arrays.copyOfRange(in,index+
1,in.length));
return root;
}
}