【LeetCode 1014】最佳观光对 Best Sightseeing Pair

中移物联ML307C模组OPENCPU笔记2 本文介绍了如何编译和运行一个DEMO程序,以官方SDK为例。 阅读详情

LeetCode 1014题,属于数组类型的题目,题意:
在这里插入图片描述
翻译成中文,就是要找数组中的两个点,满足:

  • A[i] + A[j] + i - j的值最大
  • 且 i < j

在这里插入图片描述
在这里插入图片描述
思路:
最快速的想法,就是直接暴力求解:
因为实际上就是求符合题意的两个点能获得的最大值,直接两个循环:

    public int maxScoreSightseeingPair(int[] A) {
        if (A == null || A.length == 0) return 0;
        int max = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = i + 1; j < A.length; j++) {
                if (A[i] + A[j] + i - j > max) {
                    max = A[i] + A[j] + i - j;
                }
            }
        }
        return max;
    }

但直接暴力解复杂度 O(n²),LeetCode直接超时了,所以我们要变换思路:
我们观察:A[i] + A[j] + i - j,可以拆分为:A[i] + i跟A[j] - j,所以,题目相当于,找出一个点 i,且在改点之后,有一个点 j,使得A[i] + i跟A[j] - j的和获得最大值。
我们可以想到,先遍历一遍数组,记录在当前 i可以获得的A[i] + i的最大值temp[],再第二次遍历数组,看在哪个点,可以获得temp[i[ + A[i] - i的最大值,代码:

    public int maxScoreSightseeingPair(int[] A) {
        if (A == null || A.length == 0) return 0;
        // 用于记录每个点之前,能获取的 A[i] + i的最大值
        int[] temp = new int[A.length];
        int max = Integer.MIN_VALUE;
        // 第一次遍历,用于更新 temp[]
        for (int i = 0; i < A.length - 1; i++) {
            if (A[i] + i > temp[i]) {
                // 若当前 i点的组合大于原始组合,则更新
                temp[i + 1] = A[i] + i;
            } else {
            	// 当前 i点组合未能获得更大的组合值
                temp[i + 1] = temp[i];
            }
        }
        // 第二次遍历
        for (int i = 0; i < A.length; i++) {
            if (temp[i] + A[i] - i > max) {
                max = temp[i] + A[i] - i;
            }
        }
        return max;
    }

该解法的时间复杂度为 O(n),空间复杂度为 O(n)。但该解法遍历了两次数组,而且还有空间开销,那我们可不可以只遍历一次且常数级别的空间开销呢?
其实我们发现:上面的 temp[]用于记录在这个点之前能获取的 A[i] + i组合的最大值,其实我们可以用一个变量进行记录即可,因此,修改代码,有:

    public int maxScoreSightseeingPair(int[] A) {
        if (A == null || A.length == 0) return 0;
        int i = 0, max = Integer.MIN_VALUE;
        for (int j = 1; j < A.length; j++) {
            if (A[i] + A[j] + i - j > max) {
                max = A[i] + A[j] + i - j;
            }
            // 更新 A[i] + i组合能获得最大值的下标
            if (i + A[i] < j + A[j]) {
                i = j;
            }
        }
        return max;
    }

时间复杂度 O(n),空间复杂度 O(1)
提交结果:
在这里插入图片描述

其他 LeetCode 题目解析

彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource 阅读详情

相关推荐

DS18B20温度传感器项目实战:从驱动编写到LCD显示,打造你的第一个温控系统

本文详细介绍了如何使用DS18B20温度传感器和LCD1602显示屏构建一个完整的温控系统。从硬件连接、OneWire协议实现到温度数据采集与LCD显示,全面解析了系统整合与工程化实现的关键步骤,帮助开发者快速掌握嵌入式温度监测系统的开发技巧。

weixin_42525328的博客 348

Leetcode 1014:最佳观光组合(超详细的解法!!!)

给定正整数数组 A,A[i] 表示第 i 个观光景点的评分,并且两个景点 i 和 j 之间的距离为 j - i。 一对景点(i < j)组成的观光组合的得分为(A[i] + A[j] + i - j):景点的评分之和减去它们两者之间的距离。 返回一对观光景点能取得的最高分。 示例: 输入:[8,1,5,2,6] 输出:11 解释:i = 0, j = 2, A[i] + A[j] + i -...

coordinate的博客 1947

基于PLC的冲压件自动生产线电气系统设计【附数据】

考虑到生产线的高效运行和维护简便性,选择了三菱FX系列的可编程逻辑控制器(PLC)作为核心控制单元,该型号的PLC因其高可靠性和强大的功能集,在工业自动化领域有着广泛的应用。最后,在完成初步的软件开发后,进行了多轮次的模拟测试和现场调试,逐步修正了存在的问题,最终达到了预期的功能要求。例如,对于进料环节,选用了光电传感器以精确检测物料的位置;此外,为了适应不同尺寸的工件加工需求,还特别设计了一套可调节的夹具系统,不仅提高了生产线的灵活性,同时也降低了更换模具的成本。✅ 感恩科研路上每一位志同道合的伙伴!

lagougongzuoshi的博客 1291

Leetcode—1014. 最佳观光组合【中等】

运行结果 之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

Atticus的博客 443

PX4笔记系列(二)vtol_att_control中的tiltrotor解析

update_vtol_state() 注释:采用两段切换的简单逻辑来进行过渡 当切换过渡开关后,飞机将会开始倾转动力,逐渐加速,当飞机获得足够速度后动力将会完全打到向前的位置。对于过渡返回阶段动力则是简单地倾转回来。 如果(不在向前过渡指令下): 当前vtol飞行模式: 1、旋翼模式 无操作 2、固定翼模式 令vtol飞行模式切换到过渡返回模式 3、P1过渡模式 进入过渡失败安全返回至旋翼模式 4、P2过渡模式 进入过渡失败安全返回至旋翼模式 5、过渡返回模式 记录过渡返回时间=当前时间-过渡开始

hypersonicss的博客 1878

PyCharm安装PyQt5及工具(Qt Designer、PyUIC、PyRcc)详细教程来了

Qt是常用的用户界面设计工具,而在Python中则使用PyQt这一工具包,它是Python编程语言和Qt库的成功融合。这篇博文通过图文详细介绍在PyCharm中如何完整优雅地安装配置PyQt5的所有工具包,主要内容包括PyQt5、PyQt5-tools的依赖包安装和Qt Designer、PyUIC、PyRcc三个工具的设置。最后简单演示了PyQt5的调用方式及三个工具的使用方法。

Python966的博客 3万+

LeetCode 每日一题 ---- 【1014. 最佳观光组合】

枚举右端点 j,同时维护 j 左侧的最大值。:leftnum,那么最终结果就变成了。先对题目中的式子进行变形。

是微风,是晚霞,是无可替代 654

遥感生态指数(RSEI)——四个指数的计算

遥感生态指数是在4个生态指数的基础上通过主成分变换得出的一个评价生态环境质量的指标。因此,第二部分就是要分别计算出这4个指数的值。 ①首先,是绿度指数的计算,一般用归一化植被指数(NDVI) NDVI=(NIR-Red)/(NIR+Red) 在Bandmath工具中输入NDVI计算公式 (float(b4-b3))/(b4+b3) 其中,b3、b4分别是红波段和近红外波段 ②其次,是湿度计算。 WET = c1B1 + c2B2 + c3B3...

qq_41978498的博客 9万+

LeetCode 1014. 最佳观光组合 一次遍历数组,时间复杂度O(n)

1014. 最佳观光组合 一次遍历数组,时间复杂度O(n)

weixin_60214397的博客 641

4、文化遗产数字记录的伦理框架构建

本文探讨了在数字技术快速发展的背景下,如何构建一个伦理框架以指导文化遗产的数字记录工作。文章分析了遗产保护的重要性以及当前面临的挑战,包括气候变化、全球化和技术变革等。同时,结合国际古迹遗址理事会(ICOMOS)的伦理原则和加拿大遗产专业人员协会(CAHP)的行为准则,提出了六个核心伦理类别,并讨论了其在实践中的应用。文章强调,伦理框架不仅有助于提高数字记录的质量和可持续性,还能促进专家合作、保护社区利益并确保数字遗产的长期可访问性。未来需要持续完善这一框架,以应对不断变化的技术和社会环境带来的新挑战。

7h6j5k4l3的博客 95

YOLOv8轻量化模型瘦身术:深度解析与实战LAMP剪枝 YOLOv8(2021)

YOLOv8模型LAMP剪枝技术解析与实战 本文深入探讨了LAMP剪枝技术在YOLOv8目标检测模型中的应用。针对深度学习模型部署面临的资源限制问题,LAMP剪枝通过最小化L2失真和层自适应稀疏度分配,实现了高效模型压缩。相比传统幅度剪枝的"一刀切"方法,LAMP创新性地将剪枝建模为优化问题,定义LAMP分数来衡量权重重要性,自动确定各层最佳剪枝率。文章从理论基础出发,详细解析了LAMP的核心数学公式和算法流程,并提供了完整的YOLOv8移植实战指南,包括代码结构、剪枝步骤和微调策略。通

FJN110的博客 2422

LeetCode1014. Best Sightseeing Pair

1014. Best Sightseeing Pair Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and twosightseeing spots i and jhave distance j - ibetween them. The scoreof a pair (i < j) of sightseeing spots is (A[i] + ...

RitaAndWakaka的博客 184

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Leetcode 1014.最佳观光组合(Best Sightseeing Pair)

Leetcode 1014.最佳观光组合 1 题目描述(Leetcode题目链接)   给定正整数数组 A,A[i] 表示第 i 个观光景点的评分,并且两个景点 i 和 j 之间的距离为 j - i。 一对景点(i < j)组成的观光组合的得分为(A[i] + A[j] + i - j):景点的评分之和减去它们两者之间的距离。 返回一对观光景点能取得的最高分。 输入:[8,1,5,2,6] 输出:11 解释:i = 0, j = 2, A[i] + A[j] + i - j = 8 + 5 + 0 -

qq_39378221的博客 236

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

leetcode 1014. Best Sightseeing Pair 最佳观光组合

Problem:双重循环的,当且仅当vi+vj + i - j > vi + vPre + i - jPre是才更新最大值和vpre=values[j], jPre = j,化简得到vj - vPre > j - jPre可以剪枝去重的地方是当 i < jpre,此时只需要直接计算最小值不需要进入到第二重循环,mx = max(a + vpre + i - jpre, mx);continue;

邹九的个人博客 56

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)➤GitHub地址:https://github.com/strengthen/LeetCode➤原文地址:https://www.cnblogs.com/stren...

weixin_30918415的博客 125

(Java)leetcode-1014 Best Sightseeing Pair(最佳观光组合)

从暴力到动规,到降维优化...

不思量 231

每日一道算法题Leetcode1014:Best Sightseeing Pair(最佳观光组合)

最佳观光组合题目分析题解暴力求解枚举优化总结 题目 给定正整数数组 A,A[i] 表示第 i 个观光景点的评分,并且两个景点 i 和 j 之间的距离为 j - i。 一对景点(i < j)组成的观光组合的得分为(A[i] + A[j] + i - j):景点的评分之和减去它们两者之间的距离。 返回一对观光景点能取得的最高分。 链接:link. 分析 题目要求得到 ==A[i] + A[j] + i - j(i < j)==的最大值,首先暴力两重循环肯定可以解决。但是再进一步想一想,我们可以将式

Alan0_0的博客 357

LeetCode:1014. Best Sightseeing Pair最佳观光组合(C语言)

题目描述: 给定正整数数组 A,A[i] 表示第 i 个观光景点的评分,并且两个景点 i 和 j 之间的距离为 j - i。 一对景点(i < j)组成的观光组合的得分为(A[i] + A[j] + i - j):景点的评分之和减去它们两者之间的距离。 返回一对观光景点能取得的最高分。 示例: 输入:[8,1,5,2,6] 输出:11 解释:i = 0, j = 2, A[i] + A[j] + i - j = 8 + 5 + 0 - 2 = 11 提示: 2 <= A.length <=

C/C++攻城狮 318

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

作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录题目描述题目大意解题方法日期 题目地址:https://leetcode.com/problems/best-sightseeing-pair/ 题目描述 Given an array A of positive integers, A[i] represents the valu...

负雪明烛 1534

leetcode 1014.最佳观光组合

原题如下 https://leetcode-cn.com/problems/best-sightseeing-pair/solution/ 2020年6月17日 每日一题 题解 方法一 暴力(超时) 运用暴力遍历所有的(i,j)的组合,并求出对应式子的最大值,此方法超时。 代码示例: class Solution { public int maxScoreSightseeingPair(int[] A) { int ans=Integer.MIN_VALUE; fo

zhuruihe2014的博客 1万+

1014. Best Sightseeing Pair - 最佳观光组合

Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and twosightseeing spots i and jhave distance j - ibetween them. The scoreof a pair (i < j) of sightseeing spots is (A[i] + A[j] + i- j) : the sum of th...

Lazyafei's Blog 263

1014. Best Sightseeing Pair**

1014. Best Sightseeing Pair** https://leetcode.com/problems/best-sightseeing-pair/ 题目描述 Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and two sightseei...

珍妮的选择的博客 301

Leetcode No.1014 Best SightSeeing Pair

题目:https://leetcode.com/problems/best-sightseeing-pair/ 简介: SightSeeing Score 计算:对于SightSeeing Spots的数组,The score of a pair (i < j) of sightseeing spots is (A[i] + A[j] + i - j) : the sum of the v...

SniperMarus的博客 218

leetcode 1014. Best Sightseeing Pair

一、题意 给出一个整数数组values,求values[i]+values[j]+i−jvalues[i] + values[j] + i - jvalues[i]+values[j]+i−j 最大值。 二、解法 解法: 1、将式子拆分成values[i]+ivalues[i]+ivalues[i]+i和values[j]−jvalues[j]-jvalues[j]−j 2、遍历数组,一边求到i之前的values[i]+ivalues[i]+ivalues[i]+i的最大值maxN,一边求max(maxN+

Genius_J的博客 232

leetcode 1014 best sightseeing pair

Thoughts on 1014 The final output can be divided into two parts values[i] + i and values[j] - j we need to update the maximum value for values[i] + i in each iteration and calculate the output for that certain index Solution for 1014 https://leetcode-c

weixin_41917137的博客 124

leetcode 1014 Best Sightseeing Pair 详细解答

leetcode 1014 Best Sightseeing Pair 详细解答 在这里我们可以将问题转化为 (A[i]+i)+(A[j]−j)(A[i] + i) + (A[j]-j) (A[i]+i)+(A[j]−j) 那么理所当然,我们想要 A[i] + i 越大越好,所以用一个index来保存当前A[i]+i 的下标。 具体代码如下: ...

qq_22210659的博客 198
上一篇: 源码学习 Java.lang.Comparable<T>
下一篇: 【LeetCode 1024】视频拼接 Video Stitching
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值