Created
February 11, 2019 21:26
-
-
Save amraks/d8f9ee7df9f02e4efb060bde3f65ec68 to your computer and use it in GitHub Desktop.
Top K frequent elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Leetcode https://leetcode.com/problems/top-k-frequent-elements/ | |
def topKFrequent(self, nums, k): | |
""" | |
:type nums: List[int] | |
:type k: int | |
:rtype: List[int] | |
""" | |
from collections import Counter | |
d = Counter() | |
d.update(nums) | |
return list(map(lambda x : x[0], d.most_common()[0:k])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment