class Solution:
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""
a_dict = {}
b_dict = {}
new_string = ""
new_list = []
for i in range(len(s)):
if s[i] not in a_dict:
a_dict[s[i]] = 1
else:
a_dict[s[i]] += 1
for (keys, values) in a_dict.items():
if values not in b_dict:
b_dict[values] = keys * values
else:
b_dict[values] = b_dict[values] + keys * values
new_list = sorted(list(b_dict.keys()))
for j in new_list:
new_string = b_dict[j] + new_string
return new_string
No comments:
Post a Comment