跳跃游戏 II-leetcode45-贪心-java题解

LeetCode 55 & 45:跳跃游戏与跳跃游戏 II - 贪心算法详解 跳跃游戏系列是LeetCode中经典的贪心算法问题,考察对数组遍历和最优策略的理解。本文将详细解析55题(跳跃游戏)和45题(跳跃游戏 II)的解决方案,通过图解和Java实现帮助读者掌握贪心算法的应用。 阅读详情

问题说明来源leetcode

一、问题描述

45. 跳跃游戏 II

难度中等1918

给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。

每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处:

  • 0 <= j <= nums[i]
  • i + j < n

返回到达 nums[n - 1] 的最小跳跃次数。生成的测试用例可以到达 nums[n - 1]。

示例 1:

输入: nums = [2,3,1,1,4]
输出: 2
解释: 跳到最后一个位置的最小跳跃数是 2。
     从下标为 0 跳到下标为 1 的位置,跳 1 步,然后跳 3 步到达数组的最后一个位置。

示例 2:

输入: nums = [2,3,0,1,4]
输出: 2

提示:

  • 1 <= nums.length <= 104
  • 0 <= nums[i] <= 1000

二、题解:

思考过程:

如果扫描一定范围,取其中的最大值来作为条约点可以不?

对于第一个点肯定是索引为0的,这个元素肯定是要计入的。

那么当拿到nums[0]了呢?

先对【0,nums[0]】范围的元素继续扫描,取最大的。

但是最大的好像不一定行,因为如果该最大值距离上一个踩点很近,

比如说

元素:5 4 3 2 1 2 3 3
索引:0 1 2 3 4 5 6 7

上面的结果对于第一次扫描到的4肯定不是结果

那么好像不是取最大的,而是???

对于范围【0,5】的元素,应该是考虑len - 1 - nums[i]的大小才对!

但是这样子真能找到最小跳跃步数吗?会不会还增加了一些步数?

1 . . . . . . 1 . . . . . ? . . 1 . . . . . . . 1

好像模拟不出来有什么情况,好像真的没问题。

那就这样

class Solution {
       public int jump(int[] nums) {
        if (nums.length == 1) return 0;
        int count = 0;
        int index = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[index] < nums.length - index - 1){
                count++;
                // 寻找下一个power,power 是使得len - nums[j] - j - 1最小的;
                int tmp = i;
                for (int j = i;j <= nums[index] + index; j++) {
                    if ( nums.length - nums[j] - j <= nums.length - nums[tmp] - tmp) tmp = j;
                }
                i = nums[index] + index;
                index = tmp;
            }else {
                break;
            }

        }
        return count+1;
    }
}

ok了

【中等】力扣算法题解析LeetCode45:跳跃游戏 II 问题要求计算从数组起始位置到终点的最小跳跃次数。采用贪心算法,通过维护当前跳跃边界和可到达的最远位置来优化跳跃次数。遍历数组时,每次到达边界后更新跳跃次数和边界,直到覆盖终点。算法时间复杂度为O(n),空间复杂度为O(1),高效且简洁。示例中[2,3,1,1,4]的最小跳跃次数为2,验证了算法的正确性。实际提交显示执行用时0ms,内存消耗42.1MB,性能优异。 阅读详情

相关推荐

Qt 5.15.2静态编译避坑实录:MinGW 32位版从源码到Creator配置的全流程踩坑总结

本文详细介绍了Qt 5.15.2 MinGW 32位版本的静态编译全流程,包括环境准备、配置参数优化、编译过程监控及安装后配置。重点解决了静态编译中的常见问题,如参数顺序敏感、路径引号问题等,并提供了性能对比实测数据,帮助开发者高效完成静态编译。

weixin_26749245的博客 276

LeetCode算法题6:贪心 - 跳跃游戏

一、跳跃游戏 二、跳跃游戏II

Little_ant_的博客 3946

SpyGlass Lint脚本实战:如何用TCL自动化RTL代码检查(附完整配置模板)

本文详细介绍了如何利用TCL脚本实现SpyGlass Lint工具的自动化RTL代码检查。通过构建模块化、工程化的脚本框架,文章提供了从环境搭建、核心配置、规则定制到豁免管理的完整实战指南,并附有可复用的配置模板,旨在帮助IC设计工程师构建高效、一致的代码质量检查流水线。

weixin_29204205的博客 142

力扣45.跳跃游戏Ⅱ(贪心思路详解)

从最后一个位置开始遍历,并选定该位置作为目标位置,然后从前向后查找出第一个能跳到这个位置的位置,即距离目标位置最远的位置,作为上一跳的起跳位置,然后更新这个起跳位置为目标位置,再选定这个新的目标位置,继续从前往后查找,找到距离这个新目标位置最远的起跳位置,且该起跳位置保证可以跳到新的目标位置,重复该过程直到使起跳位置变成第一个位置,返回步数。例如,对于数组 [2,3,1,2,4,2,3],初始位置是下标 0,从下标 0 出发,最远可到达下标 2。输入: nums = [2,3,1,1,4]

weixin_45863060的博客 989

一文讲透3GPP TS 36.104发射链路相关指标

3GPP是制定移动通信标准的国际组织,其36.104规范对LTE基站射频性能提出详细要求。规范主要涵盖七方面:1)基站输出功率分类标准;2)LTE信道带宽计算方法;3)TD-LTE特有的发射机关断功率及时延要求;4)信号质量指标(频率误差和EVM)及其影响因素;5)邻道泄漏比(ACLR)的45dBc标准;6)带内频谱辐射模板(OBUE)的噪声限制;7)9kHz-12.75GHz频段的带外杂散辐射要求。这些技术要求保障了LTE基站的射频性能和网络质量。

weixin_49761275的博客 4541

vasp计算练习1-Si

si的vasp训练流程

qq_41074165的博客 3309

LeetCode第45题-跳跃游戏||-java实现-图解思路与手撕代码

LeetCode第45题-跳跃游戏||-java实现-图解思路与手撕代码

weixin_45271005的博客 1120

LilyGO T-Watch学习(一)环境搭建,编译下载

1、安装arduino IDE, 安装后按照说明添加lib IDE上选择“项目->加载库->添加.ZIP库”,选择C:\Users\用户名\Documents\Arduino\libraries\下的TTGO_TWatch_Library-master.zip; 查看是否添加成功: 项目->加载库,滑到最后可看见已添加的TTGO... 参考:https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library 2、安装esp32 ardui

hxl5955的博客 2916

[LeetCode] 45. 跳跃游戏 II(java实现)贪心

[LeetCode] 45. 跳跃游戏 II(java实现)1. 题目2. 读题(需要重点注意的东西)3. 解法4. 可能有帮助的前置习题5. 所用到的数据结构与算法思想6. 总结 1. 题目 2. 读题(需要重点注意的东西) 思路(动态规划+贪心): 计算机一秒能处理8*107的数据,此题nums最大长度为104,因此如果是时间复杂度O(n2)的算法,一定会超时。 3. 解法 ---------------------------------------------------解法-----------

cloud的博客 3671

威纶通触摸屏与S7-1200 PLC通讯避坑指南:从TIA Portal配置到EasyBuilder Pro实战

本文详细解析了威纶通触摸屏与S7-1200 PLC通讯的完整流程与常见问题。从TIA Portal的安全设置、IP规划,到EasyBuilder Pro中的设备配置、数据地址映射,再到高级功能如报警、趋势图的实现,提供了一套从零到精通的实战避坑指南,帮助工程师高效稳定地完成项目集成。

weixin_29250403的博客 813

stm32h743 FM25CL64铁电存储器踩坑记录

调试FRAM经验总结: 1、跑完FRAM读写代码之后,逻分仪发现总线上只有简单、短暂的电平变化,明显不是SPI的通信数据。 (经提醒发现连片选拉高拉低都没有执行到位) 后来发现是因为片选引脚没有初始化,所以直接拉高拉低是无效的。 2、引脚成功初始化后发现CLK、MISO、MOSI数据仍不正常。通过加打印的方式发现跑到HAL_SPI_Transmit中之后还没有执行到写SPI数据寄存器的那一步就return了。 后来经提醒发现: 上图中的指针使用方式错误 后来又发现: 打印出来发现

kuniqiw的博客 3854

LeetCode第45题:Jump Game II(java实现)

题目描述: 题目解答: 在Leetcode的Discuss中多数采用贪心算法,就是当前能跳多远就跳多远,而且还存在两种贪心算法,一种是从前往后跳,一种是从后往前跳。 有一个重要的思想是:它既然能跳到前面,也可以稍微退后一点跳,结合下面的FarIndex的更新过程进行思考! 下面是贪心算法的解答的算法: class Solution { //采用贪心算法求解,每一次跳到最远,...

FaustoPatton的博客 703

SST专题(2-2)MMC-SST 输入级的工作原理及数学模型

本文研究了MMC-SST和iMMC-SST的电路结构及工作原理。系统由前级MMC电路和后级DC/DC电路组成,MMC负责电能转换和能量存储,DC/DC电路进行电压电流调节。重点分析了半桥型子模块(SM)的开关组态和工作原理,建立了平均值模型,推导了上下桥臂电压方程和环流特性。研究表明,通过合理控制子模块充放电模态可维持端口电压平衡,上下桥臂电压调控可影响网侧功率吸收,而环流特性对中压直流侧电压具有重要影响。

嵌入式老牛的博客 788

LeetCode 45. 跳跃游戏 II 题解

跳跃游戏 II” 是一个典型的贪心算法问题,通过合理选择每一步的跳跃点,可以有效地减少跳跃次数。在实际编程中,贪心算法通常用于解决优化问题,它简单且高效。然而,贪心算法并不总是能得到全局最优解,需要根据问题的具体场景来判断是否适用。希望这篇文章能帮助你更好地理解贪心算法,并在解决类似问题时能够灵活运用。

2301_77695569的博客 1250

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

【LeetCode: 45. 跳跃游戏 II + 贪心】

【LeetCode: 45. 跳跃游戏 II + 贪心】给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处: - 0

Coder_ljw的博客 787

深度学习工具包 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")

力扣最热一百题——跳跃游戏II

全网最热一百题——超详细解释,多方位分析,新手也能学会!!!

WenJGo的博客 1278

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LeetCode 45. 跳跃游戏 II(中等)

LeetCode 45. 跳跃游戏 II - 详细题解

ZeroBugX的博客 1005

力扣45-跳跃游戏II (java详细题解)

其实我们可以换一个维度,我们直接找覆盖范围,遍历每一个元素,尽可能的去增加他的覆盖范围,只要覆盖范围能大于等于终点,就直接返回true。如果一个题你觉得可以用局部最优推出全局最优,并且没有反例来反驳的话就可以用贪心来试试。该题也不好入手,我们会纠结第一步跳哪,第二步跳哪,最终能不能跳到终点。这一篇博客就到这了,如果你有什么疑问和想法可以打在评论区,或者私信我。因为本人最近都来刷贪心类的题目所以该题就默认用贪心方法来做。如果纠结某一步跳什么地方的话,那么这个题就很难想出来了。贪心方法:局部最优推出全局最优。

2302_79761426的博客 866

45. 跳跃游戏 II(leetcoe 45)

解法方法时间复杂度空间复杂度优点缺点解法 1O(n)O(1)最优效率,代码简洁逻辑可能稍难直接想到解法 2O(n^2)O(1)思路相对直观效率较低解法 3O(n^2)O(n)DP 标准思路,易于理解效率较低,空间占用多对于 LeetCode 45 跳跃游戏 II 问题,解法 1 (贪心 - 正向扫描)是最优解,具有线性的时间复杂度和常数的空间复杂度。虽然解法 2 和 3 也能解决问题,但它们的效率相对较低。在面试或实际应用中,应首选解法 1。

zempty 笔记 915

代码随想录day28 | leetcode 122.买卖股票的最佳时机II 55.跳跃游戏 45.跳跃游戏II

本题首先要清楚两点:想获得利润至少要两天为一个交易单元。这道题目可能我们只会想,选一个低的买入,再选个高的卖,再选一个低的买入…循环反复。如果想到其实最终利润是可以分解的,那么本题就很容易了!如何分解呢?假如第 0 天买入,第 3 天卖出,那么利润为:prices[3] - prices[0]。相当于(prices[3] - prices[2]) + (prices[2] - prices[1]) + (prices[1] - prices[0])。此时就是把利润分解为每天为单位的维度,而不是从 0 天到第

2302_81139517的博客 1619

【LeetCode 热题 100】45. 跳跃游戏 II

这段代码旨在解决经典的 “跳跃游戏 II” (Jump Game II) 问题。与判断“能否到达”的第一代问题不同,此问题要求在假设总能到达终点的前提下,计算出到达数组最后一个位置所需的 最小跳跃次数。该算法采用了一种非常高效的 贪心算法,其思想可以类比为 广度优先搜索 (BFS)。它不是关注每一步具体跳到哪里,而是在每一“跳”的范围内,寻找下一“跳”能到达的最远距离。算法的逻辑步骤如下:定义边界:贪心遍历:返回结果: 时空复杂度 时间复杂度:O(N) 循环:算法的核心是一个 循环,它从 遍历到 。这

最短的捷径就是绕远路,绕远路才是我的最短捷径。 1177

算法leetcode|45. 跳跃游戏 II(rust重拳出击)

给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处: 0

二当家的白帽子 1889

45. 跳跃游戏 II

本文深入解析了跳跃游戏II的贪心算法解决方案。该算法通过维护当前最远可达位置和跳跃边界两个关键变量,在一次遍历中计算出最少跳跃次数,实现了O(n)时间复杂度和O(1)空间复杂度。算法的核心在于:每当到达当前跳跃边界时进行新跳跃,并将边界更新为当前能到达的最远位置。这种策略确保了每次跳跃都是必要且最优的,从而保证总跳跃次数最少。文章通过实例跟踪、正确性证明和复杂度分析,展示了该贪心算法的高效性和可靠性,并与其他解法进行了对比,凸显了其优越性。该算法不仅解决了特定问题,更体现了贪心算法"局部最优到全局

mrjieke6的博客 1101

LeetCode 0045.跳跃游戏 II:贪心(柳暗花明又一村)

LeetCode 0045.跳跃游戏 II:贪心(柳暗花明又一村) 给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向后跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处: 0 <= j <= nums[i] i + j < n 返回到达 nums[n - 1] 的最小跳跃次数。生成的测试用例可以到达 nums[n - 1]。

<font color="Pink">Tisfy的博客</font> 923

Java描述 LeetCode,45. Jump Game II 跳跃游戏II

1-1:题目 Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of

人在江湖 786

[leetcode] 45. 跳跃游戏 II

[leetcode] 45. 跳跃游戏 II

lvhao123456789的博客 1361
上一篇: 跳跃游戏-leetcode55-贪心
下一篇: Springboot实现简单注册
xin麒
博客等级 码龄6年 110粉丝 161原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值