๐ Top K Frequent Elements
๐What I thought
- ๋ฆฌ์คํธ ๊ฐ์ ๋น๋์ โ Counter ์ฐ๋ฉด ๋์์~
- Counter ๊ฐ์ฒด๋ก ๋ง๋ค์ด์ most_common()ํจ์ ์ฐ๊น
๐ํ์ด
๐Counter
from collections import Counter
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
freq = Counter(nums).most_common(k)
return [v for v, cnt in freq]- most_common()ํจ์๋ฅผ ์ฐ๋ฉด (์์, ๋น๋์)์ ํํ๋ก ๋ฆฌ์คํธ์ ๋น๋์๊ฐ ๋์ ์์ผ๋ก ์ ์ฅ