mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0056.合并区间,添加C#
This commit is contained in:
@ -336,6 +336,32 @@ impl Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
### C#
|
||||
```csharp
|
||||
public class Solution
|
||||
{
|
||||
public int[][] Merge(int[][] intervals)
|
||||
{
|
||||
if (intervals.Length == 0)
|
||||
return intervals;
|
||||
Array.Sort(intervals, (a, b) => a[0] - b[0]);
|
||||
List<List<int>> res = new List<List<int>>();
|
||||
res.Add(intervals[0].ToList());
|
||||
for (int i = 1; i < intervals.Length; i++)
|
||||
{
|
||||
if (res[res.Count - 1][1] >= intervals[i][0])
|
||||
{
|
||||
res[res.Count - 1][1] = Math.Max(res[res.Count - 1][1], intervals[i][1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Add(intervals[i].ToList());
|
||||
}
|
||||
}
|
||||
return res.Select(x => x.ToArray()).ToArray();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<p align="center">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
|
Reference in New Issue
Block a user