标签:i++ return etc col style map order pre sort
static bool cmp(pair<char, int> a , pair<char,int> b) { return a.second>b.second; //按照value从大到小重新排序 } string frequencySort(string s) { unordered_map<char,int> m; for(auto i:s) m[i]++; vector<pair<char,int>> v; for(auto i=m.begin();i!=m.end();i++) { v.push_back(pair<char,int>(i->first, i->second)); } sort(v.begin(),v.end(),cmp); return s; }
答:将map中的pair装入到vector中,再自定义sort的cmp函数(参考leetcode451)
标签:i++ return etc col style map order pre sort
原文地址:https://www.cnblogs.com/qiezi-online/p/12790423.html