image_2023-01-06_04-11-25.png
42.7 KB
Runtime70 msBeats76.84%
Memory80 MBBeats68.31%
#N452. Minimum Number of Arrows to Burst Balloons
problem link
#solution
class Solution {
public int findMinArrowShots(int[][] points) {
int n=points.length;
//Arrays.sort(points, Comparator.comparingInt(o -> o[0]));
Arrays.sort(points, (a, b) -> Integer.compare(a[0], b[0]));
int l=points[0][0], r=points[0][1], count=1;
for(int i=0; i<n; i++){
if(points[i][0]>r || points[i][1]<l){ // not cross
l=points[i][0];
r=points[i][1];
count++;
}else{
l=Math.max(l, points[i][0]);
r=Math.min(r, points[i][1]);
}
}
return count;
}
}👍2