-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy path1353.java
31 lines (27 loc) · 859 Bytes
/
1353.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public int maxEvents(int[][] events) {
Arrays.sort(events, (a, b) -> a[0] - b[0]);
Queue<Integer> q = new PriorityQueue();
int res = 0, index = 0, n = events.length;
int l = 100000, r = 0;
for (int[] it : events) {
l = Math.min(it[0], l);
r = Math.max(it[1], r);
}
for (int i = l; i <= r; i++) {
while (index < n && events[index][0] <= i) {
q.add(events[index][1]);
index++;
}
if (q.isEmpty() && index == n) return res;
while (!q.isEmpty()) {
int pre = q.poll();
if (i <= pre) {
res++;
break;
}
}
}
return res;
}
}