일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- English
- 영어원서읽기
- 읽기
- 파비최
- 10분
- 괜찮음
- 잡생각
- 미드시청
- Daily Challenge
- FIT XR
- 개발자
- 화상영어
- 영어공부
- 월간
- 스탭퍼
- 리얼 클래스
- 매일
- 30분
- 뭐든
- 링피트
- realclass
- leetcode
- Writing
- 운동
- 쓰릴오브파이트
- 3줄정리
- 사이드
- 프로젝트
- Problem Solving
- 만화도
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.29 Today's Challenge 본문
https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/description/
Minimum Difficulty of a Job Schedule - LeetCode
Can you solve this real interview question? Minimum Difficulty of a Job Schedule - You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i). You have to finish at lea
leetcode.com
메모이제이션으로 푸는 문제
class Solution:
def minDifficulty(self, jobDifficulty: List[int], d: int) -> int:
length = len(jobDifficulty)
if len(jobDifficulty) < d:
return -1
@functools.cache
def helper(daysLeft, startJob):
if daysLeft == 1:
return max(jobDifficulty[startJob:])
maxDifficulty = jobDifficulty[startJob]
daysLeft -= 1
stop = length - startJob - daysLeft + 1
result = math.inf
for i in range(1, stop):
maxDifficulty = max(maxDifficulty, jobDifficulty[startJob + i - 1])
result = min(result, helper(daysLeft, startJob + i) + maxDifficulty)
return result
return helper(d, 0)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.31 Today's Challenge (0) | 2023.12.31 |
---|---|
2023.12.30 Today's Challenge (0) | 2023.12.30 |
2023.12.28 Today's Challenge (0) | 2023.12.28 |
2023.12.27 Today's Challenge (0) | 2023.12.27 |
2023.12.26 Today's Challenge (0) | 2023.12.26 |
Comments