mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0654.最大二叉树,添加C#版
This commit is contained in:
@ -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">
|
||||
|
Reference in New Issue
Block a user