목차

Top K Frequent Elements

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

풀이

코드

problems/leetcode/q0347.py
"""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)]