File tree Expand file tree Collapse file tree 2 files changed +35
-36
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +35
-36
lines changed Original file line number Diff line number Diff line change 2727 */
2828public class _406 {
2929
30- /**
31- * Credit: https://discuss.leetcode.com/topic/60437/java-solution-using-priorityqueue-and-linkedlist
32- */
33- public int [][] reconstructQueue (int [][] people ) {
34- Arrays .sort (people , new Comparator <int []>() {
35- public int compare (int [] p1 , int [] p2 ) {
36- return p1 [0 ] != p2 [0 ] ? Integer .compare (p2 [0 ], p1 [0 ]) : Integer .compare (p1 [1 ], p2 [1 ]);
30+ public static class Solution1 {
31+ /**
32+ * Credit: https://discuss.leetcode.com/topic/60437/java-solution-using-priorityqueue-and-linkedlist
33+ */
34+ public int [][] reconstructQueue (int [][] people ) {
35+ Arrays .sort (people , new Comparator <int []>() {
36+ public int compare (int [] p1 , int [] p2 ) {
37+ return p1 [0 ] != p2 [0 ] ? Integer .compare (p2 [0 ], p1 [0 ])
38+ : Integer .compare (p1 [1 ], p2 [1 ]);
39+ }
40+ });
41+ List <int []> list = new LinkedList ();
42+ for (int [] ppl : people ) {
43+ list .add (ppl [1 ], ppl );
3744 }
38- });
39- List <int []> list = new LinkedList ();
40- for (int [] ppl : people ) {
41- list .add (ppl [1 ], ppl );
45+ return list .toArray (new int [people .length ][]);
4246 }
43- return list .toArray (new int [people .length ][]);
4447 }
45-
4648}
Original file line number Diff line number Diff line change 55import org .junit .BeforeClass ;
66import org .junit .Test ;
77
8- /**
9- * Created by stevesun on 6/6/17.
10- */
118public class _406Test {
12- private static _406 test ;
13- private static int [][] people ;
14- private static int [][] actual ;
9+ private static _406 . Solution1 solution1 ;
10+ private static int [][] people ;
11+ private static int [][] actual ;
1512
16- @ BeforeClass
17- public static void setup () {
18- test = new _406 ();
19- }
13+ @ BeforeClass
14+ public static void setup () {
15+ solution1 = new _406 . Solution1 ();
16+ }
2017
21- @ Test
22- public void test1 () {
23- people = new int [][]{
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+ public void test1 () {
20+ people = new int [][] {
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}
You can’t perform that action at this time.
0 commit comments