首先根据身高从小到大排序如果身高相等那么根据第二个值降序排序
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
int n = people.size();
sort(people.begin(),people.end(),[](const vector<int>& a,const vector<int>& b){
return a[0]<b[0] || (a[0]==b[0]&&a[1]>b[1]);
});
vector<vector<int>> res(n);
for(int i=0;i<n;i++){
int space = 1;
space += people[i][1];
for(int j=0;j<n;j++){
if(res[j].empty()){
space--;
if(space==0){
res[j] = people[i];
break;
}
}
}
}
return res;
}
};
标签:const,people,队列,406,vector,身高,LeetCode
From: https://www.cnblogs.com/poteitoutou/p/16882390.html