| ps | |
|---|---|
| 링크 | leetcode.com/… |
| 출처 | LeetCode |
| 문제 번호 | 347 |
| 문제명 | Top K Frequent Elements |
| 레벨 | Medium |
| 분류 |
기본 |
| 시간복잡도 | O(n+klogn) |
| 인풋사이즈 | n<=10^5 |
| 사용한 언어 | python 3.14 |
| 제출기록 | 22.91MB / 3ms |
| 최고기록 | 0ms |
| 해결날짜 | 2026/04/25 |
"""Solution code for "LeetCode 347. Top K Frequent Elements".
- Problem link: https://leetcode.com/problems/top-k-frequent-elements/
- Solution link: http://www.teferi.net/ps/problems/leetcode/347
"""
import collections
from typing import List
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
return [key for key, _val in collections.Counter(nums).most_common(k)]