반응형
def solution(n, lost, reserve):
haveTrainning = []
lost.sort()
reserve.sort()
# 여유분이 있지만 잃어버린 학생
temp = []
for i in lost:
if i in reserve:
temp.append(i)
for i in temp:
lost.pop(lost.index(i))
reserve.pop(reserve.index(i))
for i in range(1, n+1):
if i not in lost:
haveTrainning.append(i)
for i in lost:
if (i-1) in reserve:
reserve.pop(reserve.index(i-1))
haveTrainning.append(i)
else:
if (i+1) in reserve:
reserve.pop(reserve.index(i+1))
haveTrainning.append(i)
answer = len(haveTrainning)
return answer
반응형
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[파이썬][프로그래머스] 동적계획법(Dynamic Programming) 정수 삼각형 (0) | 2023.01.03 |
---|---|
[파이썬][프로그래머스] 탐욕법(Greedy) 구명보트 (0) | 2022.12.19 |
[파이썬][프로그래머스] 완전탐색 피로도 (0) | 2022.11.29 |
[파이썬][프로그래머스] 완전탐색 카펫 (0) | 2022.11.28 |
[파이썬][프로그래머스] 완전탐색 소수찾기 (0) | 2022.11.27 |
댓글