위클리챌린지_7주차
코드
'''
enter leave result
[1,3,2] [1,2,3] [0,1,1]
[1,4,2,3] [2,1,3,4] [2,2,1,3]
[3,2,1] [2,1,3] [1,1,2]
[3,2,1] [1,3,2] [2,2,2]
[1,4,2,3] [2,1,4,3] [2,2,0,2]
'''
def solution(enter, leave):
n = len(enter)
answer = [0] * (n+1)
enter_idx = 0
leave_idx = 0
room = set()
while leave_idx < n:
if leave[leave_idx] in room:
room.discard(leave[leave_idx])
leave_idx += 1
continue
if enter[enter_idx] not in room:
print(room)
for man in room:
answer[man] += 1
answer[enter[enter_idx]] = len(room)
room.add(enter[enter_idx])
enter_idx += 1
return answer[1:]
print(solution([1,4,2,3],[2,1,3,4]))
결과
'''
enter leave result
[1,3,2] [1,2,3] [0,1,1]
[1,4,2,3] [2,1,3,4] [2,2,1,3]
[3,2,1] [2,1,3] [1,1,2]
[3,2,1] [1,3,2] [2,2,2]
[1,4,2,3] [2,1,4,3] [2,2,0,2]
'''
def solution(enter, leave):
n = len(enter)
answer = [0] * (n+1)
enter_idx = 0
leave_idx = 0
room = set()
while leave_idx < n:
if leave[leave_idx] in room:
room.discard(leave[leave_idx])
leave_idx += 1
continue
if enter[enter_idx] not in room:
print(room)
for man in room:
answer[man] += 1
answer[enter[enter_idx]] = len(room)
room.add(enter[enter_idx])
enter_idx += 1
return answer[1:]
print(solution([1,4,2,3],[2,1,3,4]))
Author And Source
이 문제에 관하여(위클리챌린지_7주차), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@hayeon/위클리챌린지7주차저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)