Skip to content

Commit 144bf98

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 406_Queue_Reconstruction_by_Height.java
1 parent 7be5ae7 commit 144bf98

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int[][] reconstructQueue(int[][] people) {
3+
if (people == null || people.length == 0) {
4+
return new int[][] {};
5+
}
6+
7+
List<int[]> result = new ArrayList<>();
8+
9+
Arrays.sort(people, (p1, p2) -> p2[0] == p1[0] ? p1[1] - p2[1] : p2[0] - p1[0]);
10+
11+
for (int[] person : people) {
12+
result.add(person[1], person);
13+
}
14+
15+
return result.toArray(new int[result.size()][]);
16+
}
17+
}

0 commit comments

Comments
 (0)