title: "[프로그래머스] 호텔 대실 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/155651"
description: "프로그래머스 Level 2 문제 [호텔 대실]의 풀이를 정리합니다."

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

from queue import PriorityQueue

def to_int(time):
    h, m = map(int, time.split(':'))
    return 60 * h + m
    
def solution(book_time):
    book_time = [(to_int(s), to_int(e) + 10) for s, e in book_time]
    
    timepoints = PriorityQueue()
    # MinHeap에 (시작점, +1), (끝점, -1) 형태로 저장합니다.
    for s, e in book_time:
        timepoints.put((s, +1))
        timepoints.put((e, -1))
    
    curr_cnt, max_cnt = 0, -1
    while not timepoints.empty():
        t, diff = timepoints.get()
        curr_cnt += diff
        max_cnt = max(curr_cnt, max_cnt)

    return max_cnt

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges