[프로그래머스] 호텔 대실

JinUk Lee·2023년 6월 21일
0

프로그래머스

목록 보기
33/47

https://school.programmers.co.kr/learn/courses/30/lessons/155651


import heapq

def solution(book_time):
    answer = 0
    min_book_time = []

    for i in range(len(book_time)):

        start_hour = int(book_time[i][0].split(':')[0])*60
        start_min = int(book_time[i][0].split(':')[1])
        start = start_hour+start_min

        end_hour = int(book_time[i][1].split(':')[0]) * 60
        end_min = int(book_time[i][1].split(':')[1]) + 10
        end = end_hour + end_min

        min_book_time.append([start,end])

    min_book_time.sort(key=lambda x:(x[0]))
    cnt = 1

    b = [0]

    for start, end in min_book_time:
        if start >= b[0]:
            heapq.heappop(b)
        else:
            cnt += 1
        heapq.heappush(b, end)

    answer = cnt

    return answer

회의실 그리디 문제랑 비슷한 유형의 문제였다.

문자열로 된 시간을 분으로 변환해주고, 끝나는 시간에는 +10분을 했다.

그렇게 만들어진 새로운 리스트를 회의실 갯수 구하는 방법을 사용해서 갯수를 구했다.

profile
개발자 지망생

0개의 댓글