452. Minimum Number of Arrows to Burst Balloons
Last updated
Last updated
class Solution {
public int findMinArrowShots(int[][] points) {
// use a[b] - b[0], maybe overflow, so use Integer.compare(a[0], b[0])
Arrays.sort(points, (a, b) -> Integer.compare(a[0],b[0]));
int res = 1;
int end = points[0][1];
for (int i = 1; i < points.length; i++) {
if (points[i][0] > end) {
res++;
end = points[i][1];
} else {
end = Math.min(end, points[i][1]);
}
}
return res;
}
}
/*
[[10,16],[2,8],[1,6],[7,12]]
[10 16]
[2. 8]
[1. 6]
[7 12]
*/