Leetcode 1014. Capacity To Ship Packages Within D Days
二分搜索
class Solution(object):
def shipWithinDays(self, weights, D):
"""
:type weights: List[int]
:type D: int
:rtype: int
"""
l, r, middle = max(weights), sum(weights), 0 # start the binary search strategy
while l < r:
middle = int((l + r) / 2)
# check whether this capacity(middle value) is best
days, w = 1, 0
for i, val in enumerate(weights):
w += val
if w > middle:
days += 1
w = val if days > D:
l = middle + 1
if days <= D:
r = middle return l
Leetcode 1014. Capacity To Ship Packages Within D Days的更多相关文章
- 【LeetCode】1014. Capacity To Ship Packages Within D Days 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1014. Capacity To Ship Packages Within D Days
题目如下: A conveyor belt has packages that must be shipped from one port to another within D days. The ...
- LeetCode 1011. Capacity To Ship Packages Within D Days
原题链接在这里:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 题目: A conveyor belt h ...
- Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days)
Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days) 传送带上的包裹必须在 D 天内从一个港口运送到另 ...
- 128th LeetCode Weekly Contest Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
- Leetcode: Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
- [Swift]LeetCode1011. 在 D 天内送达包裹的能力 | Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
- Capacity To Ship Packages Within D Days LT1011
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
- Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
随机推荐
- gearman相关笔记
gearman do: task: job只会在一个work上执行. 上面来自一个很好的ppt:http://www.docin.com/p-590223908.html 利用开源的Gearman框架 ...
- Java技术路线
1.计算机基础: 1.1数据机构基础: 主要学习: 1.向量,链表,栈,队列和堆,词典.熟悉 2.树,二叉搜索树.熟悉 3.图,有向图,无向图,基本概念 4.二叉搜索A,B,C类熟练,9大排序熟悉. ...
- [转]u盘读不出来怎么办大汇总
今天遇到的问题 http://www.upantool.com/jiaocheng/xiufu/2016/9958.html u盘读不出来怎么办大汇总 2016-12-14 21:42 来源: 本站整 ...
- Android下Opengl ES实现单屏幕双眼显示
http://blog.csdn.net/u011371324/article/details/68946779 默认情况下,Opengl ES使用系统提供的帧缓冲区作为绘图表面,一般情况下,如果只在 ...
- NIO、Servlet3.0、HTTP1.1
J2EE 6和Glassfish 3V正式发布了,J2EE 6正式发布了Servlet3.0, 为了能更好的对WEB2.0提供支持, 3.0添加了异步处理的机制. HTTP1.1相对于HTTP1.0的 ...
- PHP递归和非递归遍历文件夹下文件
function readDirFiles($dir){ $files= []; $queue=[realpath($dir)]; $currentPath = current($queue); wh ...
- ACM训练小结-2018年6月19日
今天题目情况如下: A题:考察图论建模+判割点.B题:考察基础数据结构的运用(STL).C题:考察数学建模+运算.(三分可解)D题:考察读题+建模+数据结构的运用.E题:考察图论+贪心.F题:考察图 ...
- 让iOS项目允许使用http协议请求
苹果官方已经默认不让开发者使用不安全的http通信协议了,而是建议开发者使用安全的https协议.若我们还是需要使用http协议可以这样配置XCode: 1.打开info.plist文件 2.点击加号 ...
- pom.xml里使用了一系列的版本的框架,配置一个版本属性,让使用版本的都引用这个属性
在pom.xml定义properties标签 <properties> <project.build.sourceEncoding>UTF-8</project.buil ...
- ubuntu 忘记root密码
Ubuntu14.04系统中,因为误操作导致管理员密码丢失或无效,并且忘记root密码,此时无法进行任何root/sudo权限操作.可以通过GRUB重新设置root密码,并恢复管理员账户到正常状态. ...