본문 바로가기
Algorithm/etc

[파이썬] 프로그래머스 : 호텔 대실 (Lv.2)

by 베짱이28호 2023. 7. 25.

[파이썬] 프로그래머스 : 호텔 대실 (Lv.2)

 

 

프로그래머스

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

programmers.co.kr

 


풀이

방향성 생각

전체 시간 범위가 1440, 입력 데이터 크기가 1000
완탐으로 특정 시간대에 몇 개의 손님이 있는지 모두 테스트 가능한 크기

 

전체코드

def solution(book_time):
    
    time = []
    for start,end in book_time:
        start = int(start[:2])*60 + int(start[-2:])
        end = int(end[:2])*60 + int(end[-2:])+10 # 청소시간 10분 체크
        time.append([start,end])
    
    st_end = list(zip(*time))
    check1,check2 = min(st_end[0]),max(st_end[1])+1 # 시작시간 최소, 마감시간 최대
    
    answer = 0
    for t in range(check1,check2):
        count = 0
        for start,end in time: # 특정 시간대 t에
            if start<=t<end : # 사용하고 있는 객실 수 카운트
                count += 1
        if count > answer : # 최대값 갱신
            answer = count
    return answer

 

 

댓글