- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem406.java
More file actions
Latest commit
43 lines (35 loc) · 881 Bytes
/
Copy pathProblem406.java
File metadata and controls
43 lines (35 loc) · 881 Bytes
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
classProblem406 {
publicstaticvoidmain(String[] args) {
}
publicint[][] reconstructQueue(int[][] people) {
int[][] out = newint[people.length][2];
ArrayList<Pair> inp = newArrayList<>();
ArrayList<Pair> res = newArrayList<>();
intj = 0;
Arrays.sort(people, (o1, o2) -> {
if (o1[0] == o2[0]) {
returno1[1] - o2[1];
}
returno2[0] - o1[0];
});
for (int[] p : people) {
inp.add(newPair(p[0], p[1]));
}
for (Paire : inp) {
res.add(e.pos, e);
}
for (Paire : res) {
out[j][0] = e.height;
out[j++][1] = e.pos;
}
returnout;
}
}
classPair {
intheight;
intpos;
publicPair(intheight, intpos) {
this.height = height;
this.pos = pos;
}
}