其他分享
首页 > 其他分享> > LeetCode 451. 根据字符出现频率排序

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;
    }
};

 

标签:mltmp,ump,auto,451,second,res,排序,LeetCode,string
来源: https://blog.csdn.net/Huadong_eddy/article/details/100176179