本题是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. Python(函数式编程)

    函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的程序设计的基本单元. ...

  2. Delphi 正则表达式起步

    Delphi 正则表达式起步 在 Delphi 中使用正则表达式, 目前 PerlRegEx 应该是首选, 准备彻底而细致地研究它. 官方网站: http://www.regular-expressi ...

  3. selenium破解数字验证码

    搞了半天,总算弄出来了,识别率还可以,普通的数字验证码 from selenium import webdriver from PIL import Image import pytesseract ...

  4. c#中类和成员的修饰符介绍

    类访问修饰符: public 访问级别最高,公共访问没有限制. internal 只允许在本程序集内访问,其他程序集或站点引用其所在的程序集无法访问此类. 例如程序集LibraryA写有ClassA, ...

  5. java return redirect

    return “/user/new” 或 return “/user/edit” 如果new页面有下拉(举例)组件,在return之前如果没有准备select所需要的数据,则return到new的页面 ...

  6. ThinkPHP框架之模型

    一.数据库配置 在父类配置ThinkPHP/Conf/convention.php中,找到数据库设置部分: 将这部分复制到我们模块的配置文件Home/Conf/config.php中,将需要的参数写上 ...

  7. ZOJ 3261 Connections in Galaxy War (逆向+带权并查集)

    题意:有N个星球,每个星球有自己的武力值.星球之间有M条无向边,连通的两个点可以相互呼叫支援,前提是对方的武力值要大于自己.当武力值最大的伙伴有多个时,选择编号最小的.有Q次操作,destroy为切断 ...

  8. 自动化测试管理平台ATMS(V1.0.1_7.29)下载

    自动化测试管理平台ATMS(V1.0.1_7.29)下载http://automationqa.com/forum.php?mod=viewthread&tid=2582&fromui ...

  9. CMD 配置静态IP与DNS

    配置静态IP与DNS # 修改IP netsh interface ip set address "网络连接" static IP地址 子网掩码 默认网关 # 修改DNS nets ...

  10. Effective C++ 条款01:视C++为一个语言联邦

    四个次语言 C Object-Oriented C++ Template C++ STL