728x90

나의 풀이
def solution(participant, completion):
participant.sort()
completion.sort()
for i in range(len(completion)):
if participant[i] != completion[i]:
return participant[i]
return participant[-1]
[다른 풀이1] Counter를 이용한 풀이
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
return list(answer.keys())[0]
[다른 풀이2] Hash를 이용한 풀이
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반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] 위장 (0) | 2022.05.24 |
|---|---|
| [프로그래머스/파이썬] 전화번호 목록 (0) | 2022.05.24 |
| [프로그래머스/MySQL] 상위 n개 레코드 (0) | 2022.05.23 |
| [프로그래머스/MySQL] 여러 기준으로 정렬하기 (0) | 2022.05.23 |
| [프로그래머스/MySQL] 동물의 아이디와 이름 (0) | 2022.05.23 |