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 8918c97 commit e07436cCopy full SHA for e07436c
top-k-frequent-elements/thispath98.py
@@ -0,0 +1,16 @@
1
+"""
2
+# Time Complexity: O(N log N)
3
+- Counter 생성: N번 순회
4
+- most common 연산: N log N
5
+# Space Compelexity: O(N)
6
+- 최악의 경우 (중복된 값이 없을 경우) N개 저장
7
8
+from collections import Counter
9
+
10
11
+class Solution:
12
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
13
+ count_dict = Counter(nums)
14
+ top_k_list = count_dict.most_common(k)
15
+ answer = [key for key, value in top_k_list]
16
+ return answer
0 commit comments