# 重建二叉树

## 思路

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



10-01 4696

09-16 2059

06-24 553

10-01 248

04-07 439

03-12 624

04-12 84

03-01 104

07-14 287

04-08 1122

06-07 55

06-26 351

06-28 73

09-08 1366

02-24 2万+

05-07 1万+

03-18 104

08-05 91

03-19 83万+

04-14 62万+

#### 在中国程序员是青春饭吗？

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客