simple python solution


  • 0
    L
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            map = {}
            for c in s:
                if c in map:
                    map[c] = map[c] + 1
                else:
                    map[c] = 1
                    
            out = ''
            for w in sorted(map, key=map.get, reverse=True):
                out += w * map[w]
    
            return out
    

Log in to reply
 

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