题意:按照字符出现次数对字符串排序。
class Solution { public: map<char, int> mp; vector<char> v[1000010]; string frequencySort(string s) { int len = s.size(); for(int i = 0; i < len; ++i){ ++mp[s[i]]; } int ma = 0; for(map<char, int>::iterator it = mp.begin(); it != mp.end(); ++it){ v[it -> second].push_back(it -> first); ma = max(ma, it -> second); } string ans = ""; for(int i = ma; i >= 1; --i){ len = v[i].size(); for(int j = 0; j < len; ++j){ for(int k = 0; k < i; ++k){ ans += v[i][j]; } } } return ans; } };