weekly study 007
from 2022-09-26 to 2022-10-02
LeetCode
435 无重叠区间
public int eraseOverlapIntervals(int[][] intervals) {
if(intervals.length == 0) {
return 0;
}
int removeCount = 0;
Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
int right = intervals[0][1];
for(int i = 1; i < intervals.length; i++) {
if(right > intervals[i][0]) {
removeCount++;
} else {
right = intervals[i][1];
}
}
return removeCount;
}
}
452 用最少数量的箭引爆气球
class Solution {
public int findMinArrowShots(int[][] points) {
if(points == null || points.length == 0) {
return 0;
}
Arrays.sort(points, Comparator.comparingInt(arr -> arr[1]));
int right = points[0][1];
int removeCount = 0;
for (int i = 1; i < points.length; i++) {
if(right >= points[i][0]) {
removeCount++;
} else {
right = points[i][1];
}
}
return points.length - removeCount;
}
}
Reading
- 掘金小册《Netty 入门与实战:仿写微信 IM 即时通讯系统》第 4 节到第 13 节