풀이 과정을 대충 설명하자면,

시간을 int 로 변환하여 저장하였고,

ArrayList에 넣어서,,,

방의 갯수를 관리하였다.

하지만 더 똑똑한 방법이 있는데

그건 다음주에..

 

import java.util.*;

class Solution {
    static class Time {
        int startTime, endTime;
        
        Time(int startTime, int endTime) {
            this.startTime = startTime;
            this.endTime = endTime;
        }
    }
    public int solution(String[][] book_time) {
        int answer = 0;
        
        PriorityQueue<Time> pq = new PriorityQueue<>((a, b) -> (a.startTime - b.startTime));
        
        for(int i=0;i<book_time.length;i++) {
            String[] in = book_time[i][0].split(":");            
            int startTime = Integer.parseInt(in[0])*100 + Integer.parseInt(in[1]);
            
            in = book_time[i][1].split(":");
            int endTime = Integer.parseInt(in[0])*100 + Integer.parseInt(in[1])+10;
            
            if(endTime % 100 >= 60) {
                endTime += 40;
            }
            pq.offer(new Time(startTime, endTime));
        }
        
        List<Integer> list = new ArrayList<>();
        
        w: while(!pq.isEmpty()) {
            Time t = pq.poll();
            
            for(int i=0;i<list.size();i++) {
                if(list.get(i)<= t.startTime) {

                    list.remove(i);
                    list.add(t.endTime);
                    continue w;
                }
            }
            
            list.add(t.endTime);

        }
        
        return list.size();
    }
}

// 14:00 ~ 16:00
// 14:00 ~ 15:50

 

+ Recent posts