Python solution using dictionary


  • 0
    C
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            temp = {}
            lst_str = set(list(s))
            for i in lst_str:
                temp[i] = s.count(i, 0, len(s))
            result = ''
            for i in sorted(temp, key=temp.get, reverse=True):
                result += i*temp[i]
            return result
    
    

Log in to reply
 

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