Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d5baec9

Browse files
authoredFeb 13, 2023
Update 630-course-schedule-iii.js
1 parent 070ca1e commit d5baec9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎630-course-schedule-iii.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {number[][]} courses
3+
* @return {number}
4+
*/
5+
const scheduleCourse = function (courses) {
6+
const compare = (a, b) => a[0] === b[0] ? 0 : (a[0] > b[0] ? -1 : 1)
7+
const queue = new PriorityQueue({ compare })
8+
courses.sort((a, b) => a[1] - b[1])
9+
let time = 0
10+
for(let e of courses) {
11+
time += e[0]
12+
queue.enqueue(e)
13+
if(time > e[1]) {
14+
const tmp = queue.dequeue()
15+
time -= tmp[0]
16+
}
17+
}
18+
return queue.size()
19+
}
20+
21+
// another
22+
23+
124
/**
225
* @param {number[][]} courses
326
* @return {number}

0 commit comments

Comments
 (0)
Please sign in to comment.