A simple Python solution

  • 0
    class Solution(object):
        def frequencySort(self, s):
            d, res = {}, ""
            for c in s:
                d[c] = d.get(c,0) + 1
            dl = sorted(d, key=d.get, reverse=True)
            for v in dl:
                res += (v * d[v]) 
            return res

Log in to reply

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