方法一: 哈希表+堆排序
class Solution {
public String frequencySort(String s) {
HashMap<Character,Integer> map = new HashMap<>();
for(int i =0;i<s.length();i++){
map.put(s.charAt(i),map.getOrDefault(s.charAt(i),0)+1);
}
PriorityQueue<Character> heap = new PriorityQueue<>((n1,n2)->(map.get(n2)-map.get(n1)));
for(Character ch : map.keySet()){
heap.add(ch);
}
StringBuilder str = new StringBuilder();
while(!heap.isEmpty()){
Character tmpCh = heap.poll();
int sum = map.get(tmpCh);
for(int i = 0;i<sum;i++)
str.append(tmpCh);
}
return str.toString();
}
}