二分搜索-在D天内送达包裹的能力
题目
在 D 天内送达包裹的能力
思路
搜索区间为$[left, right]$,初始$left=max(weights)$,$right=sum(weights)$
- 能运送完,下一搜索区间$[left, mid-1]$
- 不能送完,下一搜索区间$[mid+1, right]$
代码
1 | class Solution: |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Gua!
评论
搜索区间为$[left, right]$,初始$left=max(weights)$,$right=sum(weights)$
- 能运送完,下一搜索区间$[left, mid-1]$
- 不能送完,下一搜索区间$[mid+1, right]$
1 | class Solution: |