Movatterモバイル変換


[0]ホーム

URL:


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

Commit194b3d5

Browse files
refactor 435
1 parent4d83108 commit194b3d5

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

‎src/main/java/com/fishercoder/solutions/_435.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
packagecom.fishercoder.solutions;
22

3-
importcom.fishercoder.common.classes.Interval;
4-
53
importjava.util.Arrays;
64
importjava.util.Collections;
75

@@ -13,19 +11,19 @@ public static class Solution1 {
1311
* and https://discuss.leetcode.com/topic/65594/java-least-is-most
1412
* Sort the intervals by their end time, if equal, then sort by their start time.
1513
*/
16-
publicinteraseOverlapIntervals(Interval[]intervals) {
14+
publicinteraseOverlapIntervals(int[][]intervals) {
1715
Collections.sort(Arrays.asList(intervals), (o1,o2) -> {
18-
if (o1.end !=o2.end) {
19-
returno1.end -o2.end;
16+
if (o1[1] !=o2[1]) {
17+
returno1[1] -o2[1];
2018
}else {
21-
returno2.start -o1.start;
19+
returno2[0] -o1[0];
2220
}
2321
});
2422
intend =Integer.MIN_VALUE;
2523
intcount =0;
26-
for (Intervalinterval :intervals) {
27-
if (interval.start >=end) {
28-
end =interval.end;
24+
for (int[]interval :intervals) {
25+
if (interval[0] >=end) {
26+
end =interval[1];
2927
}else {
3028
count++;
3129
}

‎src/test/java/com/fishercoder/_435Test.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
packagecom.fishercoder;
22

3-
importcom.fishercoder.common.classes.Interval;
43
importcom.fishercoder.solutions._435;
54
importorg.junit.BeforeClass;
65
importorg.junit.Test;
@@ -17,11 +16,7 @@ public static void setup() {
1716

1817
@Test
1918
publicvoidtest1() {
20-
Intervalinterval1 =newInterval(1,100);
21-
Intervalinterval2 =newInterval(11,22);
22-
Intervalinterval3 =newInterval(1,11);
23-
Intervalinterval4 =newInterval(2,12);
24-
Interval[]intervals =newInterval[]{interval1,interval2,interval3,interval4};
19+
int[][]intervals =newint[][]{newint[]{1,100},newint[]{11,22},newint[]{1,11},newint[]{2,12}};
2520
assertEquals(2,solution1.eraseOverlapIntervals(intervals));
2621
}
2722

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp