Untitled
unknown
plain_text
2 years ago
443 B
4
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