Python/Programmers

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

Magin 2023. 2. 19. 20:42
728x90

문제)

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

알고리즘)

-그리디 알고리즘

코드)

from heapq import heappop, heappush
def solution(book_time):
    temp = []
    cnt = 0
    chk_list = [(int(s[:2])*60 + int(s[3:]), int(e[:2])*60 + int(e[3:])) for s,e in book_time]
    chk_list.sort()

    for s,e in chk_list:
        if not(temp):
            cnt += 1
            heappush(temp, e)
            continue
        if temp[0] <= s:
            heappop(temp)

        else:
            cnt += 1
        heappush(temp, e+10)
    return cnt
728x90