From b9738dad8888f3ee384a4f59fcbce56d2eb71d68 Mon Sep 17 00:00:00 2001 From: Dmitrii Ivashchenko Date: Tue, 7 Nov 2023 21:45:44 +0100 Subject: [PATCH] Create 0617-merge-two-binary-trees.cs --- csharp/0617-merge-two-binary-trees.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 csharp/0617-merge-two-binary-trees.cs diff --git a/csharp/0617-merge-two-binary-trees.cs b/csharp/0617-merge-two-binary-trees.cs new file mode 100644 index 000000000..4d0a4e486 --- /dev/null +++ b/csharp/0617-merge-two-binary-trees.cs @@ -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) + ); + } +} \ No newline at end of file