添加 0452.用最少数量的箭引爆气球 go版本

添加 0452.用最少数量的箭引爆气球 go版本
This commit is contained in:
X-shuffle
2021-08-08 23:08:58 +08:00
committed by GitHub
parent 574c434714
commit 90d0ee1f32

View File

@ -175,6 +175,30 @@ class Solution:
Go
```golang
func findMinArrowShots(points [][]int) int {
var res int =1//弓箭数
//先按照第一位排序
sort.Slice(points,func (i,j int) bool{
return points[i][0]<points[j][0]
})
for i:=1;i<len(points);i++{
if points[i-1][1]<points[i][0]{//如果前一位的右边界小于后一位的左边界,则一定不重合
res++
}else{
points[i][1] = min(points[i - 1][1], points[i][1]); // 更新重叠气球最小右边界,覆盖该位置的值,留到下一步使用
}
}
return res
}
func min(a,b int) int{
if a>b{
return b
}
return a
}
```
Javascript:
```Javascript
var findMinArrowShots = function(points) {