- pair默认对first升序,当first相同时对second升序
class Solution {
public:
vector<string> sortPeople(vector<string>& names, vector<int>& heights) {
vector<pair<int,string>> q;
for(int i = 0; i < heights.size(); i++)
q.push_back({-heights[i],names[i]});//pair默认对first升序,当first相同时对second升序
sort(q.begin(),q.end());
vector<string> res;
for(auto& p:q)
res.push_back(p.second);
return res;
}
};
标签:res,heights,second,vector,升序,2418,排序,LeetCode,first
From: https://www.cnblogs.com/Sheldon2/p/16732338.html