码迷,mamicode.com
首页 > 其他好文 > 详细

查找表_leetcode451

时间:2019-03-17 15:43:42      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:return   ali   str   font   for   ict   key   计数   找工作   

# 解题思路:字典存储计数信息 20190302 找工作期间

class Solution(object):
def frequencySort(self, s):
"""
:type s: str
:rtype: str
"""

dict1 = {}
result = str()
for i in range(len(s)):
if s[i] not in dict1:
dict1[s[i]] = 1
else:
dict1[s[i]] += 1
while len(dict1) > 0:
m = max(dict1, key=dict1.get)
result += m * dict1[m]
del dict1[m]
return result

查找表_leetcode451

标签:return   ali   str   font   for   ict   key   计数   找工作   

原文地址:https://www.cnblogs.com/lux-ace/p/10546967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!