forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_406.java
28 lines (25 loc) · 893 Bytes
/
_406.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fishercoder.solutions;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
public class _406 {
public static class Solution1 {
/**
* Credit: https://discuss.leetcode.com/topic/60437/java-solution-using-priorityqueue-and-linkedlist
*/
public int[][] reconstructQueue(int[][] people) {
Arrays.sort(people, new Comparator<int[]>() {
public int compare(int[] p1, int[] p2) {
return p1[0] != p2[0] ? Integer.compare(p2[0], p1[0])
: Integer.compare(p1[1], p2[1]);
}
});
List<int[]> list = new LinkedList();
for (int[] ppl : people) {
list.add(ppl[1], ppl);
}
return list.toArray(new int[people.length][]);
}
}
}