Skip to content

Commit 2d2a484

Browse files
Time: 71 ms (99.05%) | Memory: 34.1 MB (52.36%) - LeetSync
1 parent 268a5a8 commit 2d2a484

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution:
2+
def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int:
3+
s = []
4+
5+
for i in range(len(startTime)):
6+
s.append((startTime[i], endTime[i], profit[i]))
7+
8+
s.sort(key=lambda x: x[1])
9+
10+
dp = [[0, 0]]
11+
ends = [0]
12+
13+
for start, end, p in s:
14+
idx = bisect.bisect_right(ends, start) - 1
15+
16+
last_end, last_p = dp[len(dp) - 1]
17+
18+
if last_end == end:
19+
dp[len(dp) - 1][1] = max(dp[len(dp) - 1][1], dp[idx][1] + p)
20+
else:
21+
if last_p < dp[idx][1] + p:
22+
dp.append([end, dp[idx][1] + p])
23+
ends.append(end)
24+
25+
return dp[len(dp) - 1][1]
26+
27+
28+
29+
30+
31+

0 commit comments

Comments
 (0)