그리디 문제를 풀고싶어서 픽
수가 적어서 완전 탐색해도 상관없던 문제
마지막 문장이 문제의 실질적 조건으로 이걸 놓쳐서 문제 파악에 오래 걸렸음
def solution(n, lost, reserve):
answer = 0
clothes = [1] * n
for i in reserve:
clothes[i-1] += 1
for i in lost:
clothes[i-1] -= 1
for i in range(len(clothes)):
if 0 < i and clothes[i] == 0 and clothes[i-1] > 1:
clothes[i] += 1
clothes[i-1] -= 1
elif i < n - 1 and clothes[i] == 0 and clothes[i+1] > 1:
clothes[i] += 1
clothes[i+1] -= 1
for i in range(len(clothes)):
if clothes[i] != 0:
answer += 1
return answer # n - clothes.count(0) 으로 집계 가능