Skip to content

Commit 1c10c18

Browse files
authored
Queue Reconstruction by height
1 parent 22d0b59 commit 1c10c18

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Queue Reconstruction by height

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
static bool cmp(vector<int> a, vector<int> b)
4+
{
5+
if(a[0] == b[0]) return (a[1]>b[1]);
6+
return (a[0]<b[0]);
7+
}
8+
vector<vector<int>> reconstructQueue(vector<vector<int>>& people)
9+
{
10+
vector<vector<int>> res;
11+
12+
sort(people.begin(), people.end(), cmp);
13+
for(int i = people.size()-1; i>=0; i--)
14+
{
15+
res.insert(res.begin()+people[i][1], people[i]);
16+
}
17+
return res;
18+
}
19+
};

0 commit comments

Comments
 (0)