python solution beats 99%


  • 0
    P
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            listS = list(s)
            dictS={}  #键为s中的字母,值为出现的次数
            result=""
            for i in set(listS):
                dictS[i]=s.count(i)
            
            a=sorted(dictS.items(),reverse=True,key=lambda c:c[1])
            for i in a:
                result+=i[0]*i[1]
                
            return result
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.