Skip to content

Commit

Permalink
Merge pull request #3120 from dmitry-ivashenko/0617-merge-two-binary-…
Browse files Browse the repository at this point in the history
…trees

Create 0617-merge-two-binary-trees.cs
  • Loading branch information
tahsintunan committed Dec 7, 2023
2 parents e18fac8 + b9738da commit 33c205a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions csharp/0617-merge-two-binary-trees.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Solution {
public TreeNode MergeTrees(TreeNode root1, TreeNode root2) {
if (root1 == null) return root2;

if (root2 == null) return root1;

return new TreeNode(root1.val + root2.val,
MergeTrees(root1.left, root2.left),
MergeTrees(root1.right, root2.right)
);
}
}

0 comments on commit 33c205a

Please sign in to comment.