LeetCodeDiary

A Diary for solving LeetCode problems

View on GitHub
class Solution:
    def shipWithinDays(self, weights: List[int], D: int) -> int:
        left, right = max(weights), sum(weights)
        n = len(weights)
        while left < right:
            mid = (left+right)//2
            d, i = 0, 0
            while i < n :
                wd = 0
                while i < n and mid - wd >= weights[i]:
                    wd += weights[i]
                    i += 1
                d += 1 
            if d <= D:
                right = mid
            elif d > D:
                left = mid + 1
        return left

数组 二分查找 中等 自己写的第一个二分!

所以为啥返回的是left???

https://leetcode-cn.com/problems/capacity-to-ship-packages-within-d-days/