mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
添加 0452.用最少数量的箭引爆气球 go版本
添加 0452.用最少数量的箭引爆气球 go版本
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user