解法:
1: 按高度从高到低,高度相同时按的值从小到大排序
2:按位置插入
class Solution {
public:
vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
sort(people.begin(), people.end(), [](vector<int>& p1, vector<int>& p2){
return (p1[0] == p2[0])? p1[1] < p2[1] : p1[0] > p2[0];
});
// for(auto& p: people)
// cout<<"("<<p[0]<<","<<p[1]<<") ";
// cout<<endl;
vector<vector<int>> res;
for(auto& p : people){
res.insert(res.begin() + p[1], p);
}
return res;
}
};
网友评论