[풀이 방법]
- 시간을 다루는 문제이므로, 'HH:MM' 형태로 주어진 시간을 분 단위로 통일하여 활용한다.
- 이전 사람의 종료 시간과 현재 사람의 시작시간을 비교하여, 종료시간 + 10분(청소 시간) 보다 시작시간이 뒤에 있을 경우 기존의 방을 배정하고 아닐 경우 새로운 방을 배정한다.
[풀이 코드]
import heapq
def solution(book_time):
answer = 0
heap = []
bt = [(int(s[:2]) * 60 + int(s[3:]), int(e[:2]) * 60 + int(e[3:])) for s, e in book_time]
bt.sort()
for s, e in bt:
if not heap:
heapq.heappush(heap, e + 10)
continue
if heap[0] <= s:
heapq.heappop(heap)
else:
answer += 1
heapq.heappush(heap, e + 10)
return answer + 1
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스/python] 무인도 여행 (0) | 2023.03.03 |
---|---|
[프로그래머스/python] 귤 고르기 (0) | 2023.03.03 |
[프로그래머스/python] kakao 캐시 (0) | 2022.10.31 |
[프로그래머스/python] 카카오 문자열 압축 (0) | 2022.10.27 |
[프로그래머스/python] kakao 성격유형 검사하기 (0) | 2022.10.26 |