6 line python solusion, easy to understand


  • 0
    Y

    Use Counter to save as dictionary, sort and return.

    def frequencySort(self, s):
            dic=collections.Counter(list(s))
            dic=sorted(dic.iteritems(),key=lambda x:x[1],reverse=True)
            res=''
            for key,value in dic:
                    res+=key*value
            return res
    

Log in to reply
 

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