原题
https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/description/
解法
把区间排序后,依次取集合的交集,看有多少个交集
func findMinArrowShots(points [][]int) int {
sort.Slice(points, func(i int, j int) bool{
return points[i][0] < points[j][0]
})
count := 1
start := points[0][0]
end := points[0][1]
for i := 1; i < len(points); i++{
if points[i][0] > end{
count++
start = points[i][0]
end = points[i][1]
} else{
start = max(points[i][0], start)
end = min(points[i][1], end)
}
}
return count
}
原创文章,作者:彭晨涛,如若转载,请注明出处:https://www.codetool.top/article/leetcode452-%e7%94%a8%e6%9c%80%e5%b0%91%e6%95%b0%e9%87%8f%e7%9a%84%e7%ae%ad%e5%bc%95%e7%88%86%e6%b0%94%e7%90%83/