Python lambda sort with 256 char array


  • 0
    R
        def frequencySort(self, s):
        
            alpha = [0] * 256
            for i in xrange(0, len(s)):
                alpha[ord(s[i])] += 1
    
            s = list(s)
            
            s.sort(key=lambda a: (alpha[ord(a)], a), reverse=True)
    
            return "".join(s)
    

Log in to reply
 

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