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] =?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; + +} +```