-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
37 lines (34 loc) · 897 Bytes
/
Copy pathSolution.java
File metadata and controls
37 lines (34 loc) · 897 Bytes
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
32
33
34
35
36
37
import java.util.*;
public class Solution
{
public int scheduleCourse(int[][] courses)
{
Arrays.sort(courses, new Comparator<int[]>()
{
@Override
public int compare(int[] o1, int[] o2)
{
return o1[1] - o2[1];
}
});
PriorityQueue<Integer> endDay = new PriorityQueue<Integer>(new Comparator<Integer>()
{
@Override
public int compare(Integer o1, Integer o2)
{
return o2 - o1;
}
});
int currentDay = 0;
for (int i = 0; i < courses.length; i++)
{
currentDay += courses[i][0];
endDay.add(courses[i][0]);
if (currentDay > courses[i][1])
{
currentDay -= endDay.poll();
}
}
return endDay.size();
}
}