Update 0654.最大二叉树,添加C#版
This commit is contained in:
parent
734616dff0
commit
cbb3cf962c
|
|
@ -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">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue