Update 0654.最大二叉树,添加C#版

This commit is contained in:
eeee0717
2023-11-25 09:55:40 +08:00
parent 734616dff0
commit cbb3cf962c

View File

@ -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;
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">