Given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.
You can attend an event i at any day d where startTimei <= d <= endTimei. Notice that you can only attend one event at any time d.
Return the maximum number of events you can attend.
Example
1 2 3 4 5 6 7 8 9 10
Input: events = [[1,2],[2,3],[3,4]] Output: 3 Explanation: You can attend all the three events. One way to attend them all is as shown. Attend the first event on day 1. Attend the second event on day 2. Attend the third event on day 3.
PriorityQueue<Integer> pq = new PriorityQueue<>(); Arrays.sort(events, (a, b) -> Integer.compare(a[0], b[0])); int index = 0, res = 0, n = events.length; for (int d = 1; d <= 100000; d++) { while (index < n && events[index][0] == d) pq.offer(events[index++][1]); // 加入这个的结束时间。 while (pq.size() > 0 && pq.peek() < d) pq.poll(); if (pq.size() > 0) { res++; pq.poll(); } } return res; }