1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// @Title: 用最少数量的箭引爆气球 (Minimum Number of Arrows to Burst Balloons)
// @Author: 15816537946@163.com
// @Date: 2019-11-17 16:31:17
// @Runtime: 92 ms
// @Memory: 6.8 MB
func findMinArrowShots(points [][]int) int {
	if len(points) == 0 {
		return 0
	}

	sort.Slice(points, func(i, j int) bool {
		return points[i][1] < points[j][1]
	})

	// var ans int
	ans := 1

	end := points[0][1]

	for i := 1; i < len(points); i++ {
		if points[i][0] > end {
			ans++
			end = points[i][1]
		}
	}

	return ans
}