ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 86048 |
문제명 | 입실 퇴실 |
레벨 | Level 2 |
분류 |
애드혹 |
시간복잡도 | O(n) |
인풋사이즈 | n<=1000 |
사용한 언어 | Python |
해결날짜 | 2021/09/13 |
"""Solution code for "Programmers 86048. 입실 퇴실".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/86048
- Solution link: http://www.teferi.net/ps/problems/programmers/86048
"""
def solution(enter, leave):
people_count = len(enter)
# met_people_count[X] = {number of people who entered before X left}
# - {number of people who left before X entered}
met_people_count = [None] * people_count
leave_count = 0
for enter_count, person in enumerate(enter):
met_people_count[person - 1] = -leave_count
while leave_count < people_count:
person_to_leave = leave[leave_count]
if met_people_count[person_to_leave - 1] is None:
break
met_people_count[person_to_leave - 1] += enter_count
leave_count += 1
return met_people_count