728x90
반응형
이건... 제정신의 상태로 푼게 아닌 듯 하다...
코딩테스트를 처음 시작했을 때 풀었던 것 같은데,
그냥 기념으로 남겨두겠다.
...
인간의 사고와 가장 가까운 풀이방법.
def solution(n, lost, reserve):
answer = n - len(lost)
for lost_one in lost:
if lost_one in reserve: #여벌의 체육복이 있다면
answer += 1
lost[lost.index(lost_one)] = -1
del reserve[reserve.index(lost_one)]
else:
if lost_one == 1: #첫번호일때
if lost_one+1 in reserve and lost_one+1 not in lost:
answer+=1
del reserve[reserve.index(lost_one+1)]
else:
if lost_one-1 in reserve and lost_one-1 not in lost: #앞 번호 탐색
answer+=1
del reserve[reserve.index(lost_one-1)]
elif lost_one+1 in reserve and lost_one+1 not in lost: #뒷 번호 탐색
answer+=1
del reserve[reserve.index(lost_one+1)]
return answer
728x90
반응형
'농장 > 프로그래머스 코딩테스트' 카테고리의 다른 글
[Python 프로그래머스] 스택/큐 > 기능개발 (0) | 2021.05.06 |
---|---|
[Python 프로그래머스] 찾아라 프로그래밍 마에스터 > 폰켓몬 (0) | 2021.05.03 |
[Python 프로그래머스] 해시 > 완주하지 못한 선수 (0) | 2021.05.03 |
[Python 프로그래머스] 2021 KAKAO BLIND RECRUITMENT > 신규 아이디 추천 (0) | 2021.05.03 |
[Python 프로그래머스] Summer/Winter Coding(~2018) > 소수 만들기 (0) | 2021.05.03 |