FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/course-schedule-iii.py at master · fileset/LeetCode-Solutions · GitHub
fileset
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
course-schedule-iii.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (19 loc) · 537 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
course-schedule-iii.py
Copy path
File metadata and controls
23 lines (19 loc) · 537 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Time: O(nlogn)
# Space: O(k), k is the number of courses you can take
import
collections
import
heapq
class
Solution
(
object
):
def
scheduleCourse
(
self
,
courses
):
"""
:type courses: List[List[int]]
:rtype: int
"""
courses
.
sort
(
key
=
lambda
t_end
:
t_end
[
1
])
max_heap
=
[]
now
=
0
for
t
,
end
in
courses
:
now
+=
t
heapq
.
heappush
(
max_heap
,
-
t
)
if
now
>
end
:
now
+=
heapq
.
heappop
(
max_heap
)
return
len
(
max_heap
)
Back
|
FazBrowse Home
|
New Git URL