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 ...
随机推荐
- Loadrunder之脚本篇——参数化方法
导语 参数化旨在模拟多数据来进行测试,所以再选择参数化你明确你参数化的内容! 方法一 1.确定需要参数化的内容 2.选中需要参数化的内容 3.右键选中的内容->Replace with a Pa ...
- SQL语句 自连表查询。inner join用法,partition by ,列转行查询
use mydb1 go -- 表T_Employee2 -- Id Name Position Dept -- 1 张三 员工 市场部 -- 2 李四 经理 销售部 -- 3 王五 经理 市场部 - ...
- 服务中的 API 网关(API Gateway)
我们知道在微服务架构风格中,一个大应用被拆分成为了多个小的服务系统提供出来,这些小的系统他们可以自成体系,也就是说这些小系统可以拥有自己的数据库,框架甚至语言等,这些小系统通常以提供 Rest Api ...
- OpenGL学习进程(7)第五课:点、边和图形(二)边
本节是OpenGL学习的第五个课时,下面介绍OpenGL边的相关知识: (1)边的概念: 数学上的直线没有宽度,但OpenGL的直线则是有宽度的.同时,OpenGL的直线必须是有限长度,而不是像数学概 ...
- CSS 命名里面有大学问
其实迟迟不敢开始写关于样式里布局方面的心得, 因为大多数人眼中,哪需要管那么多,只需要最终效果达到了就行了呗. 然而,即使是如今国内外顶级大牛也不敢说自己是个优秀的 CSS 工程师. 一般大公司都是 ...
- cocos2dx打飞机项目笔记六:GameScene类和碰撞检测 boundingbox
GameScene类虽然是占用游戏最多时间的类,但是里面的东西不是很多,最重要的就是碰撞检测了,碰撞检测代码如下: void GameScene::detectionCrash() { CCArray ...
- 高通平台MSM8916LCM模块移植(一)-bootloader部分【转】
本文转载自:http://www.mobile-open.com/2016/970947.html 高通平台中的bootloader叫做LK(Little Kernel,对于LCM来说LK部分相当重要 ...
- JAVA 使用qq邮箱发送邮件
引入一个架包: gradle( "com.sun.mail:javax.mail:1.5.6", ) 代码如下: private static final String QQ_EM ...
- POJ 2431 贪心+优先队列
题意:一辆卡车距离重点L,现有油量P,卡车每前行1米耗费油量1,途中有一些加油站,问最少在几个加油站加油可使卡车到达终点或到达不了终点. 思路:运用优先队列,将能走到的加油站的油量加入优先队列中, ...
- Sublime 输入中文显示方框问号乱码
最近使用的sublime 编辑器出现了打开写好的程序,中文显示的确是方框,方框里面是问号,就是不显示中文. 然后再网上查找了一下,大概都是说是需要中文编码插件,比如converttoutf8 ...