Untitled
unknown
plain_text
a year ago
443 B
3
Indexable
class Solution { public: string frequencySort(string s) { unordered_map<char, int> f; for (char c : s) { f[c]++; } multiset<pair<int, char>, greater<>> freqSet; for (auto& [ch, freq] : f) { freqSet.insert({freq, ch}); } string res = ""; for (auto& [freq, ch] : freqSet) { res += string(freq, ch); } return res; } };
Editor is loading...
Leave a Comment