贪心
class Solution {
public int findMinArrowShots(int[][] points) {
if(points.length == 0){
return 0;
}
int res = 1;
Arrays.sort(points, new Comparator<int[]>() {
public int compare(int[] points1, int[] points2) {
long diff = (long)points1[0] - (long)points2[0];
if (diff == 0) return 0;
return diff > 0 ? 1 : -1;
}
});
for(int i = 1; i < points.length; i++){
// 气球i和i - 1不挨着
if(points[i][0] > points[i - 1][1]){
res++;
}else{
// 气球i和i - 1挨着,更新重叠气球最小右边
points[i][1] = Math.min(points[i -1][1], points[i][1]);
}
}
return res;
}
}