leetcode451】的更多相关文章

Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Th…
public class Solution { public string FrequencySort(string s) { var dic = new Dictionary<char, int>(); foreach (var c in s) { if (!dic.ContainsKey(c)) { dic.Add(c, ); } else { dic[c]++; } } var list = dic.OrderByDescending(x => x.Value).ToList();…
static bool cmp(pair<char, int> a , pair<char,int> b) { return a.second>b.second; //按照value从大到小重新排序 } string frequencySort(string s) { unordered_map<char,int> m; for(auto i:s) m[i]++; vector<pair<char,int>> v; for(auto i=m…