MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / frequencySort

Method frequencySort

String/SortCharactersByFrequency.py:53–69  ·  view source on GitHub ↗

:type s: str :rtype: str

(self, s)

Source from the content-addressed store, hash-verified

51"""
52class Solution(object):
53 def frequencySort(self, s):
54 """
55 :type s: str
56 :rtype: str
57 """
58
59 x = {}
60
61 for i in s:
62 try:
63 x[i] += 1
64 except:
65 x[i] = 1
66
67 b = sorted(x, key=lambda t: x[t], reverse=True)
68
69 return ''.join([i*x[i] for i in b])
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected