class Solution {
public:
string frequencySort(string s) {
unordered_map<char, int> map;
for (int i =0; i<s.length(); i++) {
map[s[i]]++;
}
sort(s.begin(), s.end(), [&map](char a ,char b){
return map[a]>map[b] || (map[a] == map[b] && a > b);
});
return s;
}
};
Sort Characters By Frequency
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.