解题思路:
(1)先排序,将空位留给比当前人的身高 高的人
参考网址:https://leetcode.com/problems/queue-reconstruction-by-height/discuss/427157/Three-different-C%2B%2B-solutions.-from-O(n2)-to-O(nlogn).-faster-than-99
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
auto comp=[&](vector<int> &a,vector<int> &b) {
if(a[0]<b[0]) return true;
else if(a[0]>b[0]) return false;
else if(a[1]>b[1]) return true;
else return false;
};
sort(people.begin(),people.end(),comp);
vector<vector<int>> vec(people.size(),vector<int>());
for(int i=0;i<people.size();i++) {
int index=0;
for(int j=0;j<vec.size();j++) {
if(vec[j].empty()) {
if(index==people[i][1]) {
vec[j]=people[i];
break;
}
index++;
}
}
}
return vec;
}
};