https://www.youtube.com/watch?v=HraOg7W3VAM
이번 문제는 해시와 관련된 문제이다. 해시에 대해서 많은 글을 읽었지만, 자료구조에 취약한 나는 먼소리인가.. 머리가 어지럽던 와중에 10분만에 간단하고 바로 이해되게 해주는 영상을 만났다!!
문제)
풀이)
import collections
class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
answer = collections.Counter(nums).most_common(k)
return [answer[i][0] for i in range(len(answer))]
유사한 문제 - 프로그래머스 : 완주하지 못한 선수
https://school.programmers.co.kr/learn/courses/30/lessons/42576
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
return list(answer.keys())[0]