Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5fc3f01

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /