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 7a2ab91 commit 665b9bbCopy full SHA for 665b9bb
top-k-frequent-elements/deepInTheWoodz.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ counter = dict()
4
+
5
+ for num in nums:
6
+ if num in counter:
7
+ counter[num] += 1
8
+ else:
9
+ counter[num] = 1
10
11
+ return [num[0] for num in sorted(counter.items(), key=lambda x: x[1])[-k:]]
12
0 commit comments