代码拉取完成,页面将自动刷新
'''
Description:
Version: 1.0
Autuor: Vicro
Date: 2020-10-08 21:00:02
LastEditTime: 2020-10-08 21:17:11
FilePath: \Leetcode\Chinese\1011.在-d-天内送达包裹的能力.py
'''
#
# @lc app=leetcode.cn id=1011 lang=python3
#
# [1011] 在 D 天内送达包裹的能力
#
# @lc code=start
class Solution:
def shipWithinDays(self, weights, D):
l, r = max(weights), sum(weights)
while l < r:
mid = (r - l) // 2 + l
day = self.weightWhetherWork(weights, mid)
if day > D:
l = mid + 1
else:
r = mid
return l
def weightWhetherWork(self, weights, mid):
temp = mid
day = 1
for i in weights:
if temp >= i:
temp -= i
else:
temp = mid
temp -= i
day += 1
return day
sol = Solution()
A = sol.shipWithinDays([3,2,2,4,1,4],3)
print(A)
# @lc code=end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。