티스토리 뷰
programmers.co.kr/learn/courses/30/lessons/42862#
def solution(n, lost, reserve):
answer = 0
students = [1] * n
for i in lost:
students[i-1] -= 1
for i in reserve:
students[i-1] += 1
for i in range(n):
if students[i] == 0:
if i != 0 and students[i-1] >= 2:
students[i] += 1
students[i-1] -= 1
elif i != n-1 and students[i+1] >= 2:
students[i] += 1
students[i+1] -= 1
for i in range(n):
if students[i] > 0:
answer += 1
return answer
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 도둑질 - Python (0) | 2021.03.12 |
---|---|
[프로그래머스] 베스트앨범 - Python (0) | 2021.03.03 |
[프로그래머스] K번째수 - Python (0) | 2021.02.27 |
[프로그래머스] 신규 아이디 추천 - Python (0) | 2021.02.27 |
[프로그래머스] 소수 찾기 (2) - Python (0) | 2021.02.25 |