We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0e93e0e commit 723cec8Copy full SHA for 723cec8
easy/Merge Two Binary Trees.java
@@ -0,0 +1,12 @@
1
+//617. Merge Two Binary Trees
2
+class Solution {
3
+ public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
4
+ if (root1 == null && root2 == null)
5
+ return null;
6
+ final int val = (root1 == null ? 0 : root1.val) + (root2 == null ? 0 : root2.val);
7
+ TreeNode root = new TreeNode(val);
8
+ root.left = mergeTrees(root1 == null ? null : root1.left, root2 == null ? null : root2.left);
9
+ root.right = mergeTrees(root1 == null ? null : root1.right, root2 == null ? null : root2.right);
10
+ return root;
11
+ }
12
+}
0 commit comments