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 521c32a commit 2771cadCopy full SHA for 2771cad
top-k-frequent-elements/hu6r1s.py
@@ -0,0 +1,18 @@
1
+from collections import Counter
2
+
3
+class Solution:
4
+ """
5
+ - TC
6
+ - Counter(nums): O(n)
7
+ - sorted(): O(n log n)
8
+ - 슬라이싱 및 리스트 변환: O(k)
9
+ - 전체: O(n log n)
10
+ - SP
11
+ - Counter 및 정렬된 딕셔너리 저장: O(n)
12
+ - 반환 리스트: O(k)
13
+ - 전체: O(n)
14
15
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
16
+ count_nums = Counter(nums)
17
+ count_nums = dict(sorted(count_nums.items(), reverse=True, key=lambda x: x[1])).keys()
18
+ return list(count_nums)[:k]
0 commit comments