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

Commitc50f1ee

Browse files
refactor 406
1 parente34296d commitc50f1ee

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
*/
2828
publicclass_406 {
2929

30-
/**
31-
* Credit: https://discuss.leetcode.com/topic/60437/java-solution-using-priorityqueue-and-linkedlist
32-
*/
33-
publicint[][]reconstructQueue(int[][]people) {
34-
Arrays.sort(people,newComparator<int[]>() {
35-
publicintcompare(int[]p1,int[]p2) {
36-
returnp1[0] !=p2[0] ?Integer.compare(p2[0],p1[0]) :Integer.compare(p1[1],p2[1]);
30+
publicstaticclassSolution1 {
31+
/**
32+
* Credit: https://discuss.leetcode.com/topic/60437/java-solution-using-priorityqueue-and-linkedlist
33+
*/
34+
publicint[][]reconstructQueue(int[][]people) {
35+
Arrays.sort(people,newComparator<int[]>() {
36+
publicintcompare(int[]p1,int[]p2) {
37+
returnp1[0] !=p2[0] ?Integer.compare(p2[0],p1[0])
38+
:Integer.compare(p1[1],p2[1]);
39+
}
40+
});
41+
List<int[]>list =newLinkedList();
42+
for (int[]ppl :people) {
43+
list.add(ppl[1],ppl);
3744
}
38-
});
39-
List<int[]>list =newLinkedList();
40-
for (int[]ppl :people) {
41-
list.add(ppl[1],ppl);
45+
returnlist.toArray(newint[people.length][]);
4246
}
43-
returnlist.toArray(newint[people.length][]);
4447
}
45-
4648
}

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@
55
importorg.junit.BeforeClass;
66
importorg.junit.Test;
77

8-
/**
9-
* Created by stevesun on 6/6/17.
10-
*/
118
publicclass_406Test {
12-
privatestatic_406test;
13-
privatestaticint[][]people;
14-
privatestaticint[][]actual;
9+
privatestatic_406.Solution1solution1;
10+
privatestaticint[][]people;
11+
privatestaticint[][]actual;
1512

16-
@BeforeClass
17-
publicstaticvoidsetup() {
18-
test=new_406();
19-
}
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1=new_406.Solution1();
16+
}
2017

21-
@Test
22-
publicvoidtest1() {
23-
people =newint[][]{
24-
{7,0},
25-
{4,4},
26-
{7,1},
27-
{5,0},
28-
{6,1},
29-
{5,2}
30-
};
31-
actual =test.reconstructQueue(people);
32-
CommonUtils.printArrayArray(actual);
33-
}
18+
@Test
19+
publicvoidtest1() {
20+
people =newint[][]{
21+
{7,0},
22+
{4,4},
23+
{7,1},
24+
{5,0},
25+
{6,1},
26+
{5,2}
27+
};
28+
actual =solution1.reconstructQueue(people);
29+
CommonUtils.printArrayArray(actual);
30+
}
3431
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp