input
참가명단 완주명단
output
참가하였지만 완주하지 못한 사람 1명 (이름 중복 O, 한명이 완주한 경우 다른 한명은 완주하지 못한 것)
반복문으로 리스트 순회하며 completion에 있으면 participant에서 지우고 남아있는 사람 return
-> 런타임 에러 (시간복잡도)
모범코드1
import collections def solution(participant, completion): answer = collections.Counter(participant) - collections.Counter(completion) return list(answer.keys())[0]
모범코드2
def solution(participant, completion): participant.sort() completion.sort() for p, c in zip(participant, completion): if p != c: return p return participant[-1]
모범코드3
def solution(participant, completion): answer = '' temp = 0 dic = {} for part in participant: dic[hash(part)] = part temp += int(hash(part)) for com in completion: temp -= hash(com) answer = dic[temp] return answer
notice)
list(zip([1, 2, 3], [4, 5, 6])) 결과 : [(1, 4), (2, 5), (3, 6)]
list(zip([1, 2, 3], [4, 5, 6], [7, 8, 9])) 결과 : [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
list(zip("abc", "def")) 결과 : [('a', 'd'), ('b', 'e'), ('c', 'f')]