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

Appearance settings

Latest commit

 

History

History
History
43 lines (35 loc) · 881 Bytes

File metadata and controls

43 lines (35 loc) · 881 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Problem406 {
public static void main(String[] args) {
}
public int[][] reconstructQueue(int[][] people) {
int[][] out = new int[people.length][2];
ArrayList<Pair> inp = new ArrayList<>();
ArrayList<Pair> res = new ArrayList<>();
int j = 0;
Arrays.sort(people, (o1, o2) -> {
if (o1[0] == o2[0]) {
return o1[1] - o2[1];
}
return o2[0] - o1[0];
});
for (int[] p : people) {
inp.add(new Pair(p[0], p[1]));
}
for (Pair e : inp) {
res.add(e.pos, e);
}
for (Pair e : res) {
out[j][0] = e.height;
out[j++][1] = e.pos;
}
return out;
}
}
class Pair {
int height;
int pos;
public Pair(int height, int pos) {
this.height = height;
this.pos = pos;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.