Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Programmers/Gayo/호텔_대실.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.*;

class Solution {
public int solution(String[][] book_time) {
int answer = 0;
// 손님 대기열 (입실 빠른 순)
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b)->{
if(a[0]==b[0]) return Integer.compare(a[1], b[1]);
else return Integer.compare(a[0], b[0]);
});
// 객실 관리 (종료시간 기록)
PriorityQueue<Integer> arr = new PriorityQueue<>();


for(int i=0; i<book_time.length; i++){
pq.add(new int[] {CalTime(i, 0, book_time), CalTime(i, 1, book_time)+10});
}

int cur[] = pq.poll();
arr.add(cur[1]);
while(!pq.isEmpty()){
cur = pq.poll();
if(arr.peek()<=cur[0]){
arr.poll();
arr.add(cur[1]);
}
else if(arr.peek()>cur[0]){
arr.add(cur[1]);
}
}
answer = arr.size();
return answer;
}

// 문자열 시간, 분을 분 단위 정수로 변환
public int CalTime(int i, int n, String[][] book_time){
String[] splitTime = book_time[i][n].split(":");
int hour = Integer.parseInt(splitTime[0]);
int min = Integer.parseInt(splitTime[1]);
int total = hour*60 + min;
return total;
}
}