Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3078ef

Browse files
Update 0435.无重叠区间.md
更新Java版本代码
1 parent 3131e6e commit b3078ef

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

‎problems/0435.无重叠区间.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,22 @@ public:
183183
```java
184184
class Solution {
185185
public int eraseOverlapIntervals(int[][] intervals) {
186-
if (intervals.length < 2) return 0;
187-
188-
Arrays.sort(intervals, new Comparator<int[]>() {
189-
@Override
190-
public int compare(int[] o1, int[] o2) {
191-
if (o1[1] != o2[1]) {
192-
return Integer.compare(o1[1],o2[1]);
193-
} else {
194-
return Integer.compare(o1[0],o2[0]);
195-
}
196-
}
186+
Arrays.sort(intervals, (a, b) -> {
187+
if (a[0] == a[0]) return a[1] - b[1];
188+
return a[0] - b[0];
197189
});
198190

199-
int count = 1;
200-
int edge = intervals[0][1];
201-
for (int i = 1; i < intervals.length; i++) {
202-
if (edge <= intervals[i][0]){
203-
count ++; //non overlap + 1
191+
int count = 0;
192+
int edge = Integer.MIN_VALUE;
193+
for (int i = 0; i < intervals.length; i++) {
194+
if (edge <= intervals[i][0]) {
204195
edge = intervals[i][1];
196+
} else {
197+
count++;
205198
}
206199
}
207-
return intervals.length - count;
200+
201+
return count;
208202
}
209203
}
210204
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /