Open rocksc30 opened 1 year ago
class Solution { public int eraseOverlapIntervals(int[][] intervals) { Arrays.sort(intervals, (a, b) -> { if (a[0] == b[0]) return a[1] - b[1]; return a[0] - b[0]; }); int ans = 0; for (int i = 0; i < intervals.length - 1; i++){ if (intervals[i][0] == intervals[i + 1][0]){ ans++; intervals[i + 1][1] = Math.min(intervals[i][1], intervals[i+1][1]); continue; } // 重叠 if (intervals[i + 1][0] < intervals[i][1]){ ans++; intervals[i + 1][1] = Math.min(intervals[i][1], intervals[i+1][1]); } } return ans; } }