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 0a3b42a commit 9131a4bCopy full SHA for 9131a4b
top-k-frequent-elements/mandel-17.py
@@ -0,0 +1,13 @@
1
+from typing import List
2
+
3
+class Solution:
4
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
5
+ nums_dict = {}
6
+ for n in nums:
7
+ if n not in nums_dict.keys():
8
+ nums_dict[n] = 1
9
+ else:
10
+ nums_dict[n] += 1
11
12
+ frequent_rank = sorted(nums_dict.items(), key=lambda item:item[1], reverse=True)
13
+ return [frequent_rank[j][0] for j in range(k)]
0 commit comments