Skip to content

Commit edfb9bf

Browse files
Sean PrashadSean Prashad
Sean Prashad
authored and
Sean Prashad
committed
Add Greedy subfolder
1 parent 24c253e commit edfb9bf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[][] reconstructQueue(int[][] people) {
3+
// If same height, sort by idx ascending, otherwise sort by height descending
4+
Arrays.sort(people, (a, b) -> a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]);
5+
6+
List<int[]> result = new ArrayList<>();
7+
for (int[] person : people) {
8+
result.add(person[1], person);
9+
}
10+
11+
return result.toArray(new int[result.size()][]);
12+
}
13+
}

0 commit comments

Comments
 (0)