mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Update 0435.无重叠区间.md
0435.无重叠区间C语言实现
This commit is contained in:
@ -441,7 +441,37 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C
|
||||||
|
|
||||||
|
```c
|
||||||
|
// 按照区间右边界排序
|
||||||
|
int cmp(const void * var1, const void * var2){
|
||||||
|
return (*(int **) var1)[1] - (*(int **) var2)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
int eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize) {
|
||||||
|
if(intervalsSize == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
qsort(intervals, intervalsSize, sizeof (int *), cmp);
|
||||||
|
// 记录非重叠的区间数量
|
||||||
|
int count = 1;
|
||||||
|
// 记录区间分割点
|
||||||
|
int end = intervals[0][1];
|
||||||
|
for(int i = 1; i < intervalsSize; i++){
|
||||||
|
if(end <= intervals[i][0]){
|
||||||
|
end = intervals[i][1];
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return intervalsSize - count;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### C#
|
### C#
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class Solution
|
public class Solution
|
||||||
{
|
{
|
||||||
@ -468,3 +498,4 @@ public class Solution
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user