示例代码
struct Cmp{
bool operator()(vector<int> a,vector<int> b){
if(a[0]==b[0]){
return a[1]<b[1];
}
return a[0]>b[0];
}
};
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
sort(people.begin(),people.end(),Cmp());
int len=people.size();
vector<vector<int>> res;
res.reserve(len);
for(int i=0;i<len;i++){
res.insert(res.begin()+people[i][1],people[i]);
}
return res;
}
};
效果展示