mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-12 21:50:49 +08:00
添加 0452.用最少数量的箭引爆气球.md C语言版本
This commit is contained in:
@ -218,6 +218,30 @@ var findMinArrowShots = function(points) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
C:
|
||||||
|
```c
|
||||||
|
int cmp(const void *a,const void *b)
|
||||||
|
{
|
||||||
|
return ((*((int**)a))[0] > (*((int**)b))[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
|
||||||
|
//将points数组作升序排序
|
||||||
|
qsort(points, pointsSize, sizeof(points[0]),cmp);
|
||||||
|
|
||||||
|
int arrowNum = 1;
|
||||||
|
int i = 1;
|
||||||
|
for(i = 1; i < pointsSize; i++) {
|
||||||
|
//若前一个气球与当前气球不重叠,证明需要增加箭的数量
|
||||||
|
if(points[i][0] > points[i-1][1])
|
||||||
|
arrowNum++;
|
||||||
|
else
|
||||||
|
//若前一个气球与当前气球重叠,判断并最小的x_end
|
||||||
|
points[i][1] = points[i][1] > points[i-1][1] ? points[i-1][1] : points[i][1];
|
||||||
|
}
|
||||||
|
return arrowNum;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
|
Reference in New Issue
Block a user