Skip to content

Commit 33c205a

Browse files
authored
Merge pull request neetcode-gh#3120 from dmitry-ivashenko/0617-merge-two-binary-trees
Create 0617-merge-two-binary-trees.cs
2 parents e18fac8 + b9738da commit 33c205a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

csharp/0617-merge-two-binary-trees.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Solution {
2+
public TreeNode MergeTrees(TreeNode root1, TreeNode root2) {
3+
if (root1 == null) return root2;
4+
5+
if (root2 == null) return root1;
6+
7+
return new TreeNode(root1.val + root2.val,
8+
MergeTrees(root1.left, root2.left),
9+
MergeTrees(root1.right, root2.right)
10+
);
11+
}
12+
}

0 commit comments

Comments
 (0)