406. Queue Reconstruction by Height
class Solution {
public:
vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
vector<pair<int, int>> res;
sort(people.begin(), people.end(), cmp);
for (int i = 0; i < people.size(); i++)
res.insert(res.begin() + people[i].second, people[i]);
return res;
}
private:
static bool cmp(pair<int, int> &a, pair<int, int> &b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
};