File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+
4+ class Solution {
5+ public int solution (String [][] book_time ) {
6+ int n = book_time. length;
7+ int [][] times = new int [n][2 ];
8+
9+ for (int i = 0 ; i < n; i++ ) {
10+ int start = toMinutes(book_time[i][0 ]);
11+ int end = toMinutes(book_time[i][1 ]) + 10 ;
12+
13+ times[i][0 ] = start;
14+ times[i][1 ] = end;
15+ }
16+
17+ Arrays . sort(times, (a, b) - > a[0 ] - b[0 ]);
18+
19+ PriorityQueue<Integer > pq = new PriorityQueue<> ();
20+
21+ int answer = 0 ;
22+ for (int i = 0 ; i < n; i++ ) {
23+ int start = times[i][0 ];
24+ int end = times[i][1 ];
25+
26+ while (! pq. isEmpty() && pq. peek() <= start) {
27+ pq. poll();
28+ }
29+
30+ pq. offer(end);
31+
32+ answer = Math . max(answer, pq. size());
33+ }
34+
35+ return answer;
36+ }
37+
38+ private int toMinutes (String time ) {
39+ String [] temp = time. split(" :" );
40+ int h = Integer . parseInt(temp[0 ]);
41+ int m = Integer . parseInt(temp[1 ]);
42+ return h * 60 + m;
43+ }
44+ }
45+
46+ ```
You can’t perform that action at this time.
0 commit comments