From 734616dff0402cf35029835fcf71c1ce2527509e Mon Sep 17 00:00:00 2001 From: eeee0717 <70054568+eeee0717@users.noreply.github.com> Date: Fri, 24 Nov 2023 19:01:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Update=200106.=E6=B7=BB=E5=8A=A0C#=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...从中序与后序遍历序列构造二叉树.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md index 0144fc5c..dc517480 100644 --- a/problems/0106.从中序与后序遍历序列构造二叉树.md +++ b/problems/0106.从中序与后序遍历序列构造二叉树.md @@ -1228,6 +1228,19 @@ impl Solution { } } ``` +### C# +```C# +public TreeNode BuildTree(int[] inorder, int[] postorder) +{ + if (inorder.Length == 0 || postorder.Length == null) return null; + int rootValue = postorder.Last(); + TreeNode root = new TreeNode(rootValue); + int delimiterIndex = Array.IndexOf(inorder, rootValue); + root.left = BuildTree(inorder.Take(delimiterIndex).ToArray(), postorder.Take(delimiterIndex).ToArray()); + root.right = BuildTree(inorder.Skip(delimiterIndex + 1).ToArray(), postorder.Skip(delimiterIndex).Take(inorder.Length - delimiterIndex - 1).ToArray()); + return root; +} +```

From cbb3cf962c4d223296d760cfaaad89e484b77f86 Mon Sep 17 00:00:00 2001 From: eeee0717 <70054568+eeee0717@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:55:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Update=200654.=E6=9C=80=E5=A4=A7=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=A0=91=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0654.最大二叉树.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/problems/0654.最大二叉树.md b/problems/0654.最大二叉树.md index 77d7980f..6b343840 100644 --- a/problems/0654.最大二叉树.md +++ b/problems/0654.最大二叉树.md @@ -582,6 +582,21 @@ impl Solution { } } ``` +### C# +```C# +public TreeNode ConstructMaximumBinaryTree(int[] nums) +{ + if (nums.Length == 0) return null; + int rootValue = nums.Max(); + TreeNode root = new TreeNode(rootValue); + int rootIndex = Array.IndexOf(nums, rootValue); + + root.left = ConstructMaximumBinaryTree(nums.Take(rootIndex).ToArray()); + root.right = ConstructMaximumBinaryTree(nums.Skip(rootIndex + 1).ToArray()); + return root; + +} +```

From 26816ec04f90ffcfcf7c0377ac456938dddaa2e2 Mon Sep 17 00:00:00 2001 From: eeee0717 <70054568+eeee0717@users.noreply.github.com> Date: Sun, 26 Nov 2023 10:29:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Update=200617.=E5=90=88=E5=B9=B6=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E4=BA=8C=E5=8F=89=E6=A0=91=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?C#=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0617.合并二叉树.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0617.合并二叉树.md b/problems/0617.合并二叉树.md index 18839a26..9efeb56d 100644 --- a/problems/0617.合并二叉树.md +++ b/problems/0617.合并二叉树.md @@ -788,6 +788,20 @@ impl Solution { } } ``` +### C# +```C# +public TreeNode MergeTrees(TreeNode root1, TreeNode root2) +{ + if (root1 == null) return root2; + if (root2 == null) return root1; + + root1.val += root2.val; + root1.left = MergeTrees(root1.left, root2.left); + root1.right = MergeTrees(root1.right, root2.right); + + return root1; +} +```