Leetcode 1014. Best Sightseeing Pair
本题是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的更多相关文章
- 【leetcode】1021. Best Sightseeing Pair
题目如下: Given an array A of positive integers, A[i]represents the value of the i-th sightseeing spot, ...
- 【LeetCode】1021. Best Sightseeing Pair 最佳观光组合(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [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 ...
- [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 ...
- [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 ...
- Best Sightseeing Pair LT1014
Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...
- LeetCode Maximum Length of Pair Chain
原题链接在这里:https://leetcode.com/problems/maximum-length-of-pair-chain/description/ 题目: You are given n ...
- Leetcode 1014. 在 D 天内送达包裹的能力
1014. 在 D 天内送达包裹的能力 显示英文描述 我的提交返回竞赛 用户通过次数197 用户尝试次数272 通过次数203 提交次数538 题目难度Medium 传送带上的包裹必须在 D 天 ...
- Leetcode 1014. Capacity To Ship Packages Within D Days
二分搜索 class Solution(object): def shipWithinDays(self, weights, D): """ :type weights: ...
随机推荐
- pycharm修改配置
恢复pycharm的初始设置
- 11 Spring框架 SpringDAO的JdbcTemplate
上几个章节我们探讨了Spring的IoC和AOP,这是Spring的重点,但是Spring对jdbc的支持同样我们也不能忘记,毕竟我们还要通过Spring来管理DAO框架(例如Hibernate或者M ...
- 对Servlet请求或响应进行JMockit测试
对Servlet请求及响应进行mock方法, 通过getMockInstance方法对servlet进行打桩,对servlet提供的方法进行mock,替代真正的servlet请求或响应. 参考链接: ...
- Rock-Paper-Scissors-Lizard-Spock Python实现
初学python,实现一些很有意思的小游戏是很能提高编程能力的. Rock-Paper-Scissors-Lizard-Spock http://en.wikipedia.org/wiki/Rock- ...
- Java开发资料汇编
Java开发常识资料 一.Java基础JSE 核心基础(程序设计语言): <Think in java> (参考阅读:<Core Java>JAVA2核心技术 ...
- Number使用笔记
Numbe函数用于将对象转换为数字 0 0 null 0 空 0 "" 0 true 1 false 0 date ...
- NOIP 关押罪犯
(prison.pas/c/cpp)[问题描述] S 城现有两座监狱,一共关押着 N 名罪犯,编号分别为 1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发 ...
- BUG: scheduling while atomic 分析【转】
本文转载自:https://blog.csdn.net/cfy_phonex/article/details/12090943 遇到一个典型的schedule问题. <3>[26578 ...
- Spring_通过注解配置 Bean(2)
- 防盗链&CSRF&API接口幂等性设计
防盗链技术 CSRF(模拟请求) 分析防止伪造Token请求攻击 互联网API接口幂等性设计 忘记密码漏洞分析 1.Http请求防盗链 什么是防盗链 比如A网站有一张图片,被B网站直接通过img标签属 ...