STUDY/Algorithm
[프로그래머스] LEVEL1 체육복, python3
sinawi95
2019. 10. 15. 10:58
728x90
내가 짠 코드
def solution(n, lost, reserve):
for i in range(len(reserve)):
if lost.count(reserve[i]):
lost.remove(reserve[i])
reserve[i]=-1; #비교는 하되 못빌려주는 값으로 바꿈
for i in range(len(reserve)):
tmp_rsv= reserve.pop()
if tmp_rsv==-1: # 값이 -1일때는 비교 안함
continue
if lost.count(tmp_rsv+1):
lost.remove(tmp_rsv+1)
elif lost.count(tmp_rsv-1):
lost.remove(tmp_rsv-1)
answer = n-len(lost)
return answer
_reserve = [r for r in reserve if r not in lost]
_lost = [l for l in lost if l not in reserve]
다른 사람코드 중에 위와 같은 걸 봤다. 상당히 놀라운 코드였다.
공부를 해야하는게 이런이유인가 싶더라...