Python easy to understand solution runtime in top 9%


  • 0
    J
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            d = {}
            result = ''
            for ch in s:
                d[ch] = d.get(ch,0) + 1
            l = sorted(list(set(sorted(d.values()))))[::-1]
            for i in l:    
                for key,value in d.items():
                    if i == value:
                        result += (i*key)
            return result
                
    

Log in to reply
 

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