二分搜索

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的更多相关文章

  1. 【LeetCode】1014. Capacity To Ship Packages Within D Days 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【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  ...

  3. LeetCode 1011. Capacity To Ship Packages Within D Days

    原题链接在这里:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 题目: A conveyor belt h ...

  4. Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days)

    Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days) 传送带上的包裹必须在 D 天内从一个港口运送到另 ...

  5. 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 ...

  6. 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 ...

  7. [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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. MySQL数据库(7)_MySQL 数据备份与还原

    一.数据备份 1.使用mysqldump命令备份 mysqldump命令将数据库中的数据备份成一个文本文件.表的结构和表中的数据将存储在生成的文本文件中. mysqldump命令的工作原理很简单.它先 ...

  2. [笔记]一道C语言面试题:大整数乘法

    题目:输入两个数字字符串,如“1234567890”和“987654321”,返回二者相乘的结果字符串,如本例返回为“1219326311126352690”. 来源:某500强企业面试题目 思路:从 ...

  3. 流量分析系统---redis

    1\启动redis 方法一: 修改了某些配置,具体步骤惨开下面的内容 [root@mini1 ~]# service redis stop/start 方法二: [root@mini1 bin]#cd ...

  4. PAT 天梯赛 L2-021. 点赞狂魔 【水】

    题目链接 https://www.patest.cn/contests/gplt/L2-021 题意 给出一个若干个人名,后面给出点赞的总数,以及每个赞的标签类型,输出前三个点赞狂魔,按标签类型不同数 ...

  5. 建议50:Python中的高级数据结构

    # -*- coding:utf-8 -*- ''' Collection.Array.Heapq.Bisect.Weakref.Copy以及Pprint collections模块包含了内建类型之外 ...

  6. 【HackerRank】Manasa and Stones

    Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...

  7. Nginx配置中last和break及permanent和redirect的区别

    一.不写last和break 流程就是依次执行这些rewrite rewrite break - url重写后,直接使用当前资源,不再执行location里余下的语句,完成本次请求,地址栏url不变 ...

  8. iOS上架被拒原因及解决办法

    简单的记录一下,近期APP上架所遇到的坑爹事儿吧!! 第一次提交: 第二天给了回复,内容如下: .Guideline - Performance - Software Requirements You ...

  9. Java 类及类的构造方法

    类 类是一个模子,确定对象将会拥有的特性(属性)和行为(方法). 类的特点 类时对象的类型 具有相同属性和方法的一组对象的集合 构造方法 作用就是对类进行初始化. 如果你没有定议任何构造方法的形式,J ...

  10. Kubernetes Rook

    Rook Rook 是一个开源的cloud-native storage编排, 提供平台和框架:为各种存储解决方案提供平台.框架和支持,以便与云原生环境本地集成. Rook 将存储软件转变为自我管理. ...