Simple Python solution that beats 99.79% submissions


  • 0
    X
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            if len(s) < 2:
                return s
            strlist = []
            for l in list(set(s)):
                strlist.append(l*s.count(l))
            return ''.join( sorted(strlist, key=lambda x:len(x), reverse=True) )
    

Log in to reply
 

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