Skip to content

Commit dfe9504

Browse files
committed
Solution as on 04-07-2022 09:00 pm
1 parent 5ef07a9 commit dfe9504

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// 406.✅ Queue Reconstruction by Height
2+
3+
class Solution
4+
{
5+
public:
6+
vector<vector<int>> reconstructQueue(vector<vector<int>> &people)
7+
{
8+
int n = people.size();
9+
10+
sort(people.begin(), people.end(), [&](vector<int> &a, vector<int> &b)
11+
{
12+
if(a[0] == b[0])
13+
return a[1] < b[1];
14+
return a[0] > b[0]; });
15+
16+
vector<vector<int>> res;
17+
18+
for (int i = 0; i < n; ++i)
19+
{
20+
int idx = people[i][1];
21+
res.insert(res.begin() + idx, people[i]);
22+
}
23+
24+
return res;
25+
}
26+
};

0 commit comments

Comments
 (0)