Skip to content

Commit 7dd4a7f

Browse files
authored
[20251012] PGM / LV2 / 호텔 대실 / 김수연
1 parent 4eaf367 commit 7dd4a7f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
static int toInt(String s) {return Integer.parseInt(s);}
5+
6+
public int solution(String[][] book_time) {
7+
int answer = 0;
8+
int len = book_time.length;
9+
if (len == 1) return 1;
10+
Arrays.sort(book_time, (a, b) -> a[0].compareTo(b[0]));
11+
12+
PriorityQueue<Integer> q = new PriorityQueue<>();
13+
String[] e = book_time[0][1].split(":");
14+
q.add(toInt(e[0])*60 + toInt(e[1]));
15+
16+
int idx = 1;
17+
while (!q.isEmpty()) {
18+
int curr = q.peek();
19+
String[] start = book_time[idx][0].split(":");
20+
String[] end = book_time[idx][1].split(":");
21+
22+
int sMin = toInt(start[0])*60 + toInt(start[1]);
23+
int eMin = toInt(end[0])*60 + toInt(end[1]);
24+
if (curr + 10 <= sMin) q.poll();
25+
q.add(eMin);
26+
idx++;
27+
if (idx >= len) break;
28+
}
29+
30+
return q.size();
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)