We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 124f26a commit 12faf10Copy full SHA for 12faf10
top-k-frequent-elements/prograsshopper.py
@@ -0,0 +1,8 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ from collections import defaultdict
4
+ frequent_dict = defaultdict(int)
5
+ for num in nums:
6
+ frequent_dict[num] += 1
7
+ sorted_dict = dict(sorted(frequent_dict.items(), key=operator.itemgetter(1), reverse=True))
8
+ return list(sorted_dict)[:k]
0 commit comments