1
class Solution:
2
def frequencySort(self, s: str) -> str:
3
di = Counter(s)
4
# it wont strike immediately that this is a heap kind of question.
5
heap = []
6
heapq.heapify(heap)
7
for key, val in di.items():
8
heapq.heappush(heap, (-1 * val, key))
9
# n = len(s)
10
res = ""
11
# print(heap)
12
while len(heap):
13
val, ch = heapq.heappop(heap)
14
res += ch * (-1 * val)
15
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0