题目:
题解:
class Solution:
def frequencySort(self, s: str) -> str:
count = {}
for c in s:
count[c] = count.get(c, 0) + 1
items = [(-val, key) for key, val in count.items()]
heapq.heapify(items)
res = ""
while items:
val, key = heapq.heappop()
res += key * (-val)
return res