Simple Python Solution


  • 0
    M
    class Solution(object):
        def frequencySort(self, s):
            from collections import Counter
            counter  = Counter(s)
            a_list = counter.most_common()
            result=""
            for item in a_list:
                result+=item[0]*item[1]
            return result
    

    here counter.most_common() gives list sorted by values


Log in to reply
 

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