일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- Daily Challenge
- 사이드
- English
- 개발자
- 파비최
- 잡생각
- 읽기
- Problem Solving
- leetcode
- 10분
- realclass
- 영어원서읽기
- 운동
- 화상영어
- 프로젝트
- 리얼 클래스
- 미드시청
- 월간
- 뭐든
- 3줄정리
- 매일
- 링피트
- Writing
- 쓰릴오브파이트
- 괜찮음
- FIT XR
- 스탭퍼
- 만화도
- 30분
- 영어공부
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