def solution(participant, completion):
answer = ''
for i in completion:
if i in participant:
participant.remove(i)
answer = participant[0]
return answer
>>시간초과
>>in을 사용하면서 또 for문이 사용되어 시간초과가 나는것 같다
def solution(participant, completion):
answer = ''
participant.sort()
completion.sort()
for i in range(len(completion)):
if participant[i] != completion[i]:
answer+=participant[i]
break
if answer == '':
answer+=participant[-1]
return answer
#해시를 사용한 방식
def solution(participant, completion):
sum = 0
dic = {}
for x in participant:
dic[hash(x)] = x
sum += hash(x)
for x in completion:
sum -= hash(x)
answer = dic[sum]
return answer
'코딩테스트 | python > 프로그래머스' 카테고리의 다른 글
| [프로그래머스 | python] 같은 숫자는 싫어 (0) | 2024.02.06 |
|---|---|
| [프로그래머스 | python] 전화번호 목록 (0) | 2024.02.06 |
| [프로그래머스 | python] 다리를 지나는 트럭 >> 다시 풀어보기 (0) | 2024.02.06 |
| [프로그래머스 | python] 덧칠하기 (0) | 2023.10.20 |
| [프로그래머스 | python] 바탕화면 정리 (0) | 2023.10.20 |