Python simple

  • 0

    Not sure why this question is medium difficulty.

    from collections import Counter
    class Solution(object):
        def topKFrequent(self, words, k):
            c = Counter(words)
            items = [ (-value, key) for key, value in c.items() ]
            return list(map(lambda i: i[1], items[:k]))

Log in to reply

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