File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments