Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cbb3cf9

Browse files
committed
Update 0654.最大二叉树,添加C#版
1 parent 734616d commit cbb3cf9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎problems/0654.最大二叉树.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ impl Solution {
582582
}
583583
}
584584
```
585+
### C#
586+
```C#
587+
public TreeNode ConstructMaximumBinaryTree(int[] nums)
588+
{
589+
if (nums.Length == 0) return null;
590+
int rootValue = nums.Max();
591+
TreeNode root = new TreeNode(rootValue);
592+
int rootIndex = Array.IndexOf(nums, rootValue);
593+
594+
root.left = ConstructMaximumBinaryTree(nums.Take(rootIndex).ToArray());
595+
root.right = ConstructMaximumBinaryTree(nums.Skip(rootIndex + 1).ToArray());
596+
return root;
597+
598+
}
599+
```
585600

586601
<p align="center">
587602
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /