本题是leetcode121这道题的翻版,做法完全一样,也是扫一遍数组,维护两个值,一个是a[i]+i的最大值,另一个是a[i]+a[j]+i-j的最大值.

class Solution:
def maxScoreSightseeingPair(self, A: List[int]) -> int:
best, ret = 0, 0
for i, v in enumerate(A):
ret = max(ret, best + v - i)
best = max(best, i + v)
return ret

Leetcode 1014. Best Sightseeing Pair的更多相关文章

  1. 【leetcode】1021. Best Sightseeing Pair

    题目如下: Given an array A of positive integers, A[i]represents the value of the i-th sightseeing spot, ...

  2. 【LeetCode】1021. Best Sightseeing Pair 最佳观光组合(Python)

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

  3. [Swift]LeetCode1014. 最佳观光组合 | Best Sightseeing Pair

    Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...

  4. [LeetCode] Find K-th Smallest Pair Distance 找第K小的数对儿距离

    Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...

  5. [LeetCode] Maximum Length of Pair Chain 链对的最大长度

    You are given n pairs of numbers. In every pair, the first number is always smaller than the second ...

  6. Best Sightseeing Pair LT1014

    Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...

  7. LeetCode Maximum Length of Pair Chain

    原题链接在这里:https://leetcode.com/problems/maximum-length-of-pair-chain/description/ 题目: You are given n  ...

  8. Leetcode 1014. 在 D 天内送达包裹的能力

    1014. 在 D 天内送达包裹的能力  显示英文描述 我的提交返回竞赛   用户通过次数197 用户尝试次数272 通过次数203 提交次数538 题目难度Medium 传送带上的包裹必须在 D 天 ...

  9. Leetcode 1014. Capacity To Ship Packages Within D Days

    二分搜索 class Solution(object): def shipWithinDays(self, weights, D): """ :type weights: ...

随机推荐

  1. beego——事务处理和命令模式

    1.事务处理 ORM 可以简单的进行事务操作. o := NewOrm() err := o.Begin() // 事务处理过程 ... ... // 此过程中的所有使用 o Ormer 对象的查询都 ...

  2. maven项目,去除jar包中的不想要的依赖关系

    解释:就是说项目中要用到某一个a.jar包,通过maven引入了之后,也自动的导入了该jar包所依赖的包,这里就会存在一个问题,如果a.jar包依赖b.jar这个项目的1.0版本,可是我的项目中已经有 ...

  3. mysql中int(M) tinyint(M)中M的作用

    原先对mysql不太理解,但也没有报错.但理解的不够深入.这次补上. 原来以为int(11)是指11个字节,int(10)就是10个字节.我错了. http://zhidao.baidu.com/li ...

  4. 【笔记】H5自适应(待)

    参考: 1.盒子模型:http://www.cnblogs.com/sunyunh/archive/2012/09/01/2666841.html 2.浮动:http://www.w3school.c ...

  5. zero-base coordinate 和one-base coordinate

    zero-base和one-base是生信会经常碰到的两套坐标系统. zero-base是半开放式的,是不包括该点的,zero-base的文件有:bed;bam one-base是封闭式的,是包括该点 ...

  6. Git服务器的Gitosis安装配置及gitignore的使用方法

    Git服务器Gitosis安装设置 1.安装 openssh服务器 sudo apt-get install openssh-server openssh-client 2.创建个人公钥和私钥 在默认 ...

  7. java可变参数列表的实现

    参数就是我们调用一个方法时需要传入得数据,在方法中可能需要参数协助处理数据或者对参数进行解析处理以达到我们希望得到的数据和结果. 平常我们在写一个方法时,我们能确定需要传入什么样的参数以及参数的个数, ...

  8. 使用springmvc时报错HTTP Status 400 -

    这个错误大多是因为,jsp的form表单提交的字段类型和后台接收字段类型不匹配造成的(例如,form中为String,后台接收为Integer). 我这里就是jsp表单中的日期数据没有写明类型,然后用 ...

  9. Pycharm for mac 快捷键

    cmd b 跳转到声明处(cmd加鼠标) opt + 空格 显示符号代码 (esc退出窗口 回车进入代码) cmd []光标之前/后的位置 opt + F7 find usage cmd backsp ...

  10. MyEclipse安装git插件

    安装egit插件的步骤(安装egit不成功的原因主要是下载的egit版本不适合当前使用的eclipse版本).先检查自己MyEclipse适用egit的版本. 查看自己MyEclipse版本,如下图: ...