O(n) one liner Python solution, using Counters


  • 0
    Z
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            return "".join([item[0]*item[1] for item in collections.Counter(s).most_common()])
    

Log in to reply
 

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