Skip to content

Commit 6fdb734

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 630_Course_Schedule_III.java
1 parent 0511bd5 commit 6fdb734

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int scheduleCourse(int[][] courses) {
3+
int n = courses.length;
4+
if (n == 0)
5+
return 0;
6+
Arrays.sort(courses, (a, b) -> a[1] - b[1]);
7+
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> b - a);
8+
int start = 0;
9+
for (int[] course : courses) {
10+
start += course[0];
11+
pq.offer(course[0]);
12+
if (start > course[1]) {
13+
start -= pq.poll();
14+
}
15+
}
16+
return pq.size();
17+
}
18+
}

0 commit comments

Comments
 (0)