1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public TreeNode mergeTrees(TreeNode t1, TreeNode t2) { if (t1 != null && t2 != null) { TreeNode node = new TreeNode(); node.val = t1.val + t2.val; node.right = mergeTrees(t1.right, t2.right); node.left = mergeTrees(t1.left, t2.left); return node; } else if (t1 != null) { return t1; } else if (t2 != null) { return t2; } return null; } }
|