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 c527927 commit 119514cCopy full SHA for 119514c
top-k-frequent-elements/jeldo.py
@@ -0,0 +1,9 @@
1
+from collections import Counter
2
+import heapq
3
+
4
5
+class Solution:
6
+ # O(nlogn)
7
+ def topKFrequent(self, nums: list[int], k: int) -> list[int]:
8
+ ls = [(key, value) for key, value in Counter(nums).items()] # O(n)
9
+ return [key for _, key in heapq.nlargest(n=k, iterable=ls)] # O(nlogn)
0 commit comments