-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 2115 ms (48.35%), Space: 17.8 MB (20.25%) - LeetHub
- Loading branch information
1 parent
857643d
commit d7a13fd
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
1723-find-minimum-time-to-finish-all-jobs/1723-find-minimum-time-to-finish-all-jobs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Solution: | ||
def minimumTimeRequired(self, jobs: List[int], k: int) -> int: | ||
answer = sum(jobs) | ||
# v = [False] * len(jobs) | ||
wt = [0] * k | ||
jobs.sort() | ||
def bt(idx,wt): | ||
nonlocal answer,k | ||
if idx == len(jobs): | ||
answer = min(answer,max(wt)) | ||
return | ||
|
||
for i in range(len(wt)): | ||
if jobs[idx] + wt[i] <= answer: | ||
wt[i] += jobs[idx] | ||
bt(idx+1,wt) | ||
wt[i] -= jobs[idx] | ||
if wt[i] == 0: | ||
break | ||
bt(0,wt) | ||
return answer |