题目
Given a string, sort it in decreasing order based on the frequency of characters.
解题思路
使用一个计数器,然后按频率从大到小排序,再拼回去
代码
from collections import Counter
class Solution:
def frequencySort(self, s: str) -> str:
return ''.join(k * v for k, v in sorted(Counter(s).items(), key=lambda x: x[1], reverse=True))