23.01.05 Today’s Leetcode
452. Minimum Number of Arrows to Burst Balloons (medium)
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
points.sort()
last_point = points[0][1]
res = 1
for point in points:
if point[0] > last_point:
res += 1
last_point = point[1]
last_point = min(point[1], last_point)
return res
class Solution {
public int findMinArrowShots(int[][] points) {
if (points == null || points.length == 0) {
return 0;
}
Arrays.sort(points, Comparator.comparingInt(o -> o[1])); //Using Integer.compare() to avoid edge case
int count = 1;
int end = points[0][1];
for (int[] point : points) {
int start = point[0];
if (start > end) {
count++;
end = point[1];
}
}
return count;
}
}