일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로젝트
- 쓰릴오브파이트
- 읽기
- 파비최
- 사이드
- 뭐든
- FIT XR
- Problem Solving
- 스탭퍼
- Writing
- 영어원서읽기
- 미드시청
- 3줄정리
- 링피트
- 영어공부
- 개발자
- 잡생각
- 30분
- 만화도
- 리얼 클래스
- 10분
- leetcode
- English
- Daily Challenge
- 월간
- 괜찮음
- 매일
- realclass
- 화상영어
- 운동
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.02.22 Today's Challenge 본문
https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/
Capacity To Ship Packages Within D Days - LeetCode
Capacity To Ship Packages Within D Days - A conveyor belt has packages that must be shipped from one port to another within days days. The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor
leetcode.com
이런 문제를 바이너리 서치를 통해 풀 수 있고만..
class Solution:
def shipWithinDays(self, weights: List[int], days: int) -> int:
l, r = max(weights), sum(weights)
def shipDays(shipCapacity: int) -> int:
days = 1
capacity = 0
for weight in weights:
if capacity + weight > shipCapacity:
days += 1
capacity = weight
else:
capacity += weight
return days
while l < r:
m = (l + r) // 2
if shipDays(m) <= days:
r = m
else:
l = m + 1
return l
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.02.24 Today's Challenge (0) | 2023.02.24 |
---|---|
2023.02.23 Today's Challenge (0) | 2023.02.23 |
2023.02.21 Today's Challenge (0) | 2023.02.21 |
2023.02.20 Today's Challenge (0) | 2023.02.20 |
2023.02.19 Today's Challenge (0) | 2023.02.19 |
Comments