Untitled

 avatar
unknown
plain_text
a year ago
613 B
4
Indexable
class Solution {
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights) {
        vector<string> ans;
        vector<pair<string, int>> nameHeightPair;
        for (int i=0; i<names.size(); ++i) {
            nameHeightPair.emplace_back(pair{names[i], heights[i]});
        }
        auto cmp = [&](pair<string, int> a, pair<string, int> b){ return a.second > b.second; };
        sort(nameHeightPair.begin(), nameHeightPair.end(), cmp);
        for (int i=0; i<nameHeightPair.size(); ++i) {
            ans.emplace_back(nameHeightPair[i].first);
        }
        return ans;
    }
};
Editor is loading...
Leave a Comment