nums는 숫자로 이루어진 배열입니다.
가장 자주 등장한 숫자를 k 개수만큼 return 해주세요.
def top_k(nums, k):
dic = {}
for i in nums:
dic[i] = nums.count(i) # 풀이과정1
a = sorted(dic, key = lambda x : dic[x], reverse=True) # 풀이과정2
b = a[:k] # 풀이과정3
return b
from collections import Counter
def top_k(nums, k):
dic = dict(Counter(nums)) # 풀이과정1
a = sorted(dic, key = lambda x : dic[x], reverse=True) # 풀이과정2
b = a[:k] # 풀이과정3
return b