문제링크: 완주하지 못한 선수
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️ |
| 풀이시간 | 5분 |
| 제출횟수 | 2 |
| 인터넷검색유무 | no |
🍒 My Code
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]
💡 What I learned
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
hash() : key-value 중 키를 생성해주는 함수. 실행할 때마다 값이 달라질 수 있음.