프로그래머스 - 코딩테스트 연습 - 해시 - 완주하지 못한 선수
문제
https://programmers.co.kr/learn/courses/30/lessons/42576
풀이
from collections import defaultdict
def solution(participant, completion):
completes = defaultdict(int)
for name in completion:
completes[name] += 1
for name in participant:
if name in completes and completes[name] > 0:
completes[name] -= 1
else:
return name
Collections.Counter
모듈을 이용한 풀이
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
return list(answer.keys())[0]