Skip to content

Instantly share code, notes, and snippets.

@bhaveshmunot1
Created June 7, 2020 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhaveshmunot1/8a84d536e033266a04d6ee592a61044e to your computer and use it in GitHub Desktop.
Save bhaveshmunot1/8a84d536e033266a04d6ee592a61044e to your computer and use it in GitHub Desktop.
Leetcode #406: Queue Reconstruction by Height
bool comparator(const vector<int> &x, const vector<int> &y) {
return (x[0] > y[0]) || ((x[0] == y[0]) && (x[1] < y[1]));
}
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
vector<vector<int>> answer;
sort(people.begin(), people.end(), comparator);
for (auto &x:people) {
answer.insert(answer.begin()+x[1], x);
}
return answer;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment