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: ...
随机推荐
- Linux基础——centos 跳过管理员密码进行登录(单用户模式、救援模式)
这里列举了两种更改或者取消管理员密码登录Linux系统的方法,其实两种方法类似,都是想方设法跳过用户认定,直接更改用户文件.更改密码的过程. 为了跳过系统正常启动过程中的某些步骤,必须知道大致的系统启 ...
- day14生成器
生成器 我自己想写个可迭代的,——生成器生成器的本质就是迭代器因此生成器的所有好处都和迭代器一样但是生成器是我们自己写的python代码生成器的实现有两种方式:1.生成器函数2.生成器表达式 def ...
- xpath(待补充)
from lxml import etree html=""" <div> <ul> <li>1</li> <li ...
- Java集合(1):ArrayList
Java容器类的用途是“保存对象”,分为两类:Map——存储“键值对”组成的对象:Collection——存储独立元素.Collection又可以分为List和Set两大块.List保持元素的顺序(有 ...
- vue移动端 滚动 鼠标按下效果
<div class="item" :id="item.RowID" @touchstart="touchstart(item.RowID)&q ...
- 基于Promise对象的新一代Ajax API--fetch
***************************************************************** #fetch Request 使用isomorphic-fetch发 ...
- 20145109 实验二 Java面向对象程序设计
实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 S.O.L.I.D原则: ...
- StrStr,判断一个字符串是不是另一个字符串的字串,并返回子串的位置
public int strStr(String haystack, String needle) { if(haystack == null || needle == null) { return ...
- JDK_如何查看安装的jdk是32位还是64位?
1. 1.1.32位系统只能装 32位 jdk 1.2.64位系统,安装的 32位JDK 和 64位JDK 是不同的目录 1.2.1.32位的路径 类似:C:\Program Files (x86)\ ...
- 求中位数,O(n)的java实现【利用快速排序折半查找中位数】
查找无序数组的中位数,要想时间复杂度为O(n)其实用计数排序就能很方便地实现,在此讨论使用快速排序进行定位的方法. 1.中位数定义 2.算法思想 3.Java代码实现 4.时间复杂度分析 5.附录 中 ...