There was an error while loading. Please reload this page.
1 parent 6a891c2 commit a26d4edCopy full SHA for a26d4ed
Kangli/Hash Table/sortCharactersByFrequency.py
@@ -0,0 +1,10 @@
1
+from operator import itemgetter
2
+class Solution(object):
3
+ def frequencySort(self, s):
4
+ d, st = {}, ""
5
+ for c in s:
6
+ d[c] = 1 if c not in d else d[c] + 1
7
+ arr = sorted(d.items(), key=itemgetter(1), reverse = True)
8
+ for pair in arr:
9
+ st += pair[0]*pair[1]
10
+ return st
0 commit comments