@@ -0,0 +1,1738 @@
+package mtbt;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Definition for a binary tree node.%0A */%0A%0Aclass TreeNode %7B%0A%0A    int val;%0A    TreeNode left;%0A    TreeNode right;%0A%0A    TreeNode(int x) %7B%0A        val = x;%0A    %7D%0A%7D%0A%0Aclass Solution %7B%0A    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) %7B%0A%0A        if(t1 == null) %7B%0A            return t2;%0A        %7D%0A        if(t2 == null) %7B%0A            return t1;%0A        %7D%0A%0A        t1.val = t1.val + t2.val;%0A        t1.left = mergeTrees(t1.left, t2.left);%0A        t1.right = mergeTrees(t1.right, t2.right);%0A        return t1;%0A    %7D%0A%7D%0A%0Apublic class Answer %7B%0A    public static void main(String%5B%5D args) %7B%0A%0A        int%5B%5D arr1 = %7B 1, 3, 2, 5 %7D;%0A        int%5B%5D arr2 = %7B 2, 1, 3, 8, 4, 6, 7 %7D;%0A%0A        TreeNode t1 = createTree(arr1);%0A        TreeNode t2 = createTree(arr2);%0A%0A        Solution sol = new Solution();%0A        TreeNode ret = sol.mergeTrees(t1, t2);%0A%0A        System.out.println(ret);%0A    %7D%0A%0A    static TreeNode createTree(int%5B%5D arr) %7B%0A%0A        List%3CTreeNode%3E tree = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C arr.length; i++) %7B%0A            TreeNode node = new TreeNode(arr%5Bi%5D);%0A            tree.add(node);%0A        %7D%0A%0A        // %E8%8E%B7%E5%8F%96%E6%A0%91%E7%9A%84%E5%B1%82%E7%BA%A7(%E4%B8%8D%E5%8C%85%E6%8B%AC%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9)%0A        int hierarchy = arr.length / 2 - 1;%0A%0A        // %E4%BB%8E%E6%A0%B9%E5%BC%80%E5%A7%8B%E8%AE%BE%E7%BD%AE%E5%B7%A6%E5%8F%B3%E5%8F%B6%E5%AD%90%E8%8A%82%E7%82%B9%0A        for (int parentIndex = 0; parentIndex %3C hierarchy; parentIndex++) %7B%0A            tree.get(parentIndex).left = tree.get(parentIndex * 2 + 1);%0A            tree.get(parentIndex).right = tree.get(parentIndex * 2 + 2);%0A        %7D%0A%0A        // %E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E7%88%B6%E8%8A%82%E7%82%B9%0A        tree.get(hierarchy).left = tree.get(hierarchy * 2 + 1);%0A        if(arr.length %25 2 == 1) %7B%0A            tree.get(hierarchy).right = tree.get(hierarchy * 2 + 2);%0A        %7D%0A        return tree.get(0);%0A    %7D%0A%7D%0A

add `merge two binary trees` solution