Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5fc3f01

Browse files
authored
Create 1353. Maximum Number of Events That Can Be Attended
1 parent 8f972d9 commit 5fc3f01

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public int maxEvents(int[][] events) {
3+
Arrays.sort(events,(a,b)->a[0]-b[0]);
4+
5+
int day=0,index=0,n=events.length,result=0;
6+
7+
PriorityQueue<Integer> pq = new PriorityQueue<>();
8+
9+
while(!pq.isEmpty() || index<n){
10+
if(pq.isEmpty()){
11+
day = events[index][0];
12+
}
13+
while(index<n && events[index][0]<=day){
14+
pq.offer(events[index][1]);
15+
index++;
16+
}
17+
pq.poll();
18+
day++;
19+
result++;
20+
while(!pq.isEmpty() && pq.peek()<day){
21+
pq.poll();
22+
}
23+
}
24+
return result;
25+
}
26+
}

0 commit comments

Comments
 (0)