O(n) lazy Python solution


  • 0
    J
    class Solution(object):
        def frequencySort(self, s):
            """
            :type s: str
            :rtype: str
            """
            rs = Counter(s)
            return ''.join([x[0] * x[1] for x in sorted(rs.items(), key=lambda o:o[1], reverse=True)])

Log in to reply
 

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