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