Skip to content

Commit d59d79d

Browse files
author
lightmen
committed
add top-k-frequent-elements.py
1 parent c4ce371 commit d59d79d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution(object):
2+
def topKFrequent(self, nums, k):
3+
"""
4+
:type nums: List[int]
5+
:type k: int
6+
:rtype: List[int]
7+
"""
8+
return [c for c, t in collections.Counter(nums).most_common(k)]

0 commit comments

Comments
 (0)