Published:
Updated:

  • Reference
  • ์นด์šดํ„ฐ ์“ฐ๋ฉด ๋งค์šฐ ์‰ฝ๊ฒŒ ํ’€๋ฆฌ๋Š” ๋ฌธ์ œ


Solution

import collections
from typing import List


class Solution:
    def topKFrequent(self, nums: List[int], k: int) -> List[int]:
        answer = []

        counter = collections.Counter(nums)
        tmp = counter.most_common(k)
        for t in tmp:
            answer.append(t[0])

        return answer

Leave a comment