def solution(n, lost, reserve):
answer = 0
lst=[0]*(n+1)
for i in range(1,len(lst)):
if i in lost and i in reserve:
lst[i]=1
elif i in reserve:
lst[i]=2
elif i in lost:
lst[i]=0
else:
lst[i]=1
for j in range(1,len(lst)):
if j==1:
if lst[j]==2 and lst[j+1]==0:
lst[j]=1
lst[j+1]=1
elif j==len(lst)-1:
if lst[j]==2 and lst[j-1]==0:
lst[j]=1
lst[j-1]=1
else:
if lst[j]==2 and lst[j-1]==0:
lst[j]=1
lst[j-1]=1
elif lst[j]==2 and lst[j+1]==0:
lst[j]=1
lst[j+1]=1
for k in lst[1:]:
if k>0:
answer+=1
return answer
바람직하지 않은 방법.
def solution(n, lost, reserve):
# reserve, lost 중복된 사람은 제거
_reserve = [r for r in reserve if r not in lost]
_lost = [l for l in lost if l not in reserve]
# 여분이 있는 사람 중 그 사람의 앞, 뒷사람이 lost에 있는지 확인하여
# lost에 있다면 제거
for r in _reserve:
f = r - 1
b = r + 1
if f in _lost:
_lost.remove(f)
elif b in _lost:
_lost.remove(b)
return n - len(_lost)