LeetCode 451. 根据字符出现频率排序

题目描述:

解法:

class Solution {
public:
    string frequencySort(string s) {
        unordered_map<char, int> ump;
        for (const auto& str : s)
            ump[str]++;
        multimap<int, char,greater<int>> mltmp;
        for (auto it : ump)
            mltmp.insert({ it.second,it.first });
        string res;
        for (auto it : mltmp) {
            int t = it.first;
            while (t--)
                res += it.second;
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/oneDongHua/p/14264005.html