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

Commitf21b148

Browse files
refactor 646
1 parent811b58d commitf21b148

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,26 @@ Now, we define a pair (c, d) can follow another pair (a, b) if and only if b < c
2121
*/
2222
publicclass_646 {
2323

24-
/**
25-
* credit: https://discuss.leetcode.com/topic/96804/java-o-nlog-n-time-o-1-space
26-
*/
27-
publicintfindLongestChain(int[][]pairs) {
28-
Arrays.sort(pairs, (o1,o2) ->o1[1] -o2[1]);
29-
intresult =0;
30-
intn =pairs.length;
31-
inti = -1;
32-
while (++i <n) {
33-
result++;
34-
intcurEnd =pairs[i][1];
35-
while (i +1 <n &&pairs[i +1][0] <=curEnd) {
36-
/**This means, we'll keep incrementing i until pairs[i+1][0] is
37-
* exactly greater than curEnd.*/
38-
i++;
24+
publicstaticclassSolution1 {
25+
/**
26+
* credit: https://discuss.leetcode.com/topic/96804/java-o-nlog-n-time-o-1-space
27+
*/
28+
publicintfindLongestChain(int[][]pairs) {
29+
Arrays.sort(pairs, (o1,o2) ->o1[1] -o2[1]);
30+
intresult =0;
31+
intn =pairs.length;
32+
inti = -1;
33+
while (++i <n) {
34+
result++;
35+
intcurEnd =pairs[i][1];
36+
while (i +1 <n &&pairs[i +1][0] <=curEnd) {
37+
/**This means, we'll keep incrementing i until pairs[i+1][0] is
38+
* exactly greater than curEnd.*/
39+
i++;
40+
}
3941
}
42+
returnresult;
4043
}
41-
returnresult;
4244
}
4345

4446
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@
88

99
publicclass_646Test {
1010

11-
privatestatic_646test;
11+
privatestatic_646.Solution1solution1;
1212
privatestaticint[][]pairs;
1313

1414
@BeforeClass
1515
publicstaticvoidsetup() {
16-
test =new_646();
16+
solution1 =new_646.Solution1();
1717
}
1818

1919
@Test
2020
publicvoidtest1() {
2121
pairs =newint[][]{
22-
{1,2},
23-
{2,3},
24-
{5,6},
25-
{3,4}
22+
{1,2},
23+
{2,3},
24+
{5,6},
25+
{3,4}
2626
};
27-
assertEquals(3,test.findLongestChain(pairs));
27+
assertEquals(3,solution1.findLongestChain(pairs));
2828
}
2929

3030
@Test
3131
publicvoidtest2() {
3232
pairs =newint[][]{
33-
{9,10},
34-
{-9,9},
35-
{-6,1},
36-
{-4,1},
37-
{8,10},
38-
{7,10},
39-
{9,10},
40-
{2,10}
33+
{9,10},
34+
{-9,9},
35+
{-6,1},
36+
{-4,1},
37+
{8,10},
38+
{7,10},
39+
{9,10},
40+
{2,10}
4141
};
42-
assertEquals(2,test.findLongestChain(pairs));
42+
assertEquals(2,solution1.findLongestChain(pairs));
4343
}
4444

4545
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp