mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
更新0435 无重叠区间 java版本右边界解法中排序的判断逻辑
This commit is contained in:
@ -184,13 +184,14 @@ public:
|
||||
class Solution {
|
||||
public int eraseOverlapIntervals(int[][] intervals) {
|
||||
Arrays.sort(intervals, (a, b) -> {
|
||||
if (a[0] == a[0]) return a[1] - b[1];
|
||||
return a[0] - b[0];
|
||||
// 按照区间右边界升序排序
|
||||
return a[1] - b[1];
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
int edge = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < intervals.length; i++) {
|
||||
// 若上一个区间的右边界小于当前区间的左边界,说明无交集
|
||||
if (edge <= intervals[i][0]) {
|
||||
edge = intervals[i][1];
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user