首页 > 编程语言 > 详细

451. 根据字符出现频率排序

时间:2020-11-23 16:58:26      阅读:20      评论:0      收藏:0      [点我收藏+]

技术分享图片
技术分享图片

class Solution(object):
    def frequencySort(self, s):
        """
        :type s: str
        :rtype: str
        """
        mydict = {}
        for item in s:
            if item in mydict.keys():
                mydict[item] += 1
            else:
                mydict[item] = 1
        newlist = sorted(mydict.items(), key=lambda x: x[1], reverse=True)
        res = ""
        for i in newlist:
            res += "".join(i[0] * i[1])
        return res

451. 根据字符出现频率排序

原文:https://www.cnblogs.com/panweiwei/p/14024883.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!