class Solution {
public int findMinArrowShots(int[][] points) {
int n = points.length;
if (n == 1) {
return 1;
}
Arrays.sort(points, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return Integer.compare(o1[0], o2[0]);
}
});
int result = 0, i = n - 1;
while (i > -1) {
int j = i - 1, li = points[i][0];
while (j > -1 && li <= points[j][1]) {
j--;
}
i = j;
result += 1;
}
return result;
}
}
Leetcode 452. 用最少数量的箭引爆气球
2024-07-20 06:32:05 40 阅读