8000 Add python solution · qilingit/Leetcode@4cd5105 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cd5105

Browse files
committed
Add python solution
1 parent 6efe174 commit 4cd5105

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def frequencySort(self, s: str) -> str:
3+
s_dict = {}
4+
for c in s:
5+
if not c in s_dict:
6+
s_dict[c] = s.count(c)
7+
sorted_s_dict = {k: v for k, v in sorted(s_dict.items(),
8+
key=lambda item: item[1],
9+
reverse=True)}
10+
output = ''
11+
for c, nb in sorted_s_dict.items():
12+
output += c * nb
13+
14+
return output

0 commit comments

Comments
 (0)
0