본문 바로가기
Coding Test/Programmers

[Programmers] Lv 2. 호텔 대실

by song.ift 2023. 4. 3.

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

 

프로그래머스

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

programmers.co.kr

 

function solution(book_time) {
    let [rooms, livinig, empty] = [0, [], []];
    const GetTime = (n) => Number(n[0]) * 60 + Number(n[1]);

    book_time = book_time.map(([entrance, leave]) => [GetTime(entrance.split(":")), GetTime(leave.split(":"))]).sort((a, b) => a[0] - b[0]);
    
    book_time.forEach(([entrance, leave]) => {
        livinig = livinig.filter(([num, livingLeave]) => {
            return livingLeave + 10 > entrance 
            ? true : (function () {
                empty.push(num);
                return false;
            })();
        });

        !empty.length ? livinig.push([++rooms, leave]) : livinig.push([empty.pop(), leave]);
    });
    
    return rooms;
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/blob/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/unrated/155651.%E2%80%85%ED%98%B8%ED%85%94%E2%80%85%EB%8C%80%EC%8B%A4/%ED%98%B8%ED%85%94%E2%80%85%EB%8C%80%EC%8B%A4.js

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글