LeetCode 55. 跳跃游戏 ( 回溯 dp 贪心

55. Jump Game(跳跃游戏)三种解法(C++ & 注释) 55. Jump Game(跳跃游戏)1. 题目描述2.2.1 解题思路2.2 实例代码2.2.1 解题思路2.2 实例代码2.2.1 解题思路2.2 实例代码2. 参考资料 1. 题目描述 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3步到达最后一个位置。 示例 2 阅读详情

这个题字节一面做过 不过当时没想到好的解法

首先能写出一个回溯的搜索算法:

class Solution {
    private boolean[] vis;
    private boolean dfs(int[] nums,int cur){
        if(cur==nums.length-1){
            return true;
        }
        boolean rs=false;
        vis[cur]=true;
        for(int i=1;i<=nums[cur];i++){
            // 向右/向左
            // 👆 指正,这里是不需要向左跳的,不过即使如此也过不了qaq
            if(cur+i<nums.length&&!vis[cur+i]){
                vis[cur+i]=true;
                rs=rs||dfs(nums,cur+i);
                vis[cur+i]=false;
            }
        }
        return rs;
    } 
    public boolean canJump(int[] nums) {
        vis=new boolean[nums.length];
        return dfs(nums,0);
    }
}

超时

突然想到这个题很适合用dp来做:

class Solution {
    public boolean canJump(int[] nums) {
        // dp[i]表示从第i个位置出发,能否到达终点
        // 递推公式:dp[i]=dp[i+1] || dp[i+2] || ... || dp[i+nums[i]]
        boolean[] dp=new boolean[nums.length];
        dp[dp.length-1]=true;
        for(int i=dp.length-2;i>=0;i--){
            // 从当前点,判断所有他能到达的点,看能否到达
            for(int j=1;j<=nums[i];j++){
                if(dp[i+j]){
                    dp[i]=true;
                    break;
                }
            }
        }
        return dp[0];
    }
}

虽然挺慢的

最妙的还是这个(,虽然不是不能马上想到,这个题dp应该是能马上想到的

class Solution {
    public boolean canJump(int[] nums) {
        // reach表示能通过跳跃到达的最远位置
        int reach=0;
        for(int i=0;i<nums.length;i++){
            if(i>reach){
                // 当前遍历到的位置,是不能通过跳跃到达的
                // 那么自然也到不了终点
                return false;
            }
            reach=Math.max(reach,nums[i]+i);
        }
        // 上述循环走完,说明对于终点,也是可以通过跳跃到达
        return true;
    }
}

 

LeetCode 55. 跳跃游戏 I 贪心三种思路 + 动态规划 跳跃游戏 I LeetCode 55 力扣 55. 跳跃游戏 动态规划 时间复杂度 O(n2)O(n^2)O(n2), 空间复杂度O(n)O(n)O(n) 数组记录当前元素是否可以到达,1表示可以到达,0表示不可到达 状态转移:(dp[j] == 1) && (nums[j] >= i - j)时,dp[i] = dp[j]; ⚠️j要从后往前进行遍历,找到dp[i]的值后break,不然会超时 bool canJump(vector<int>& nums 阅读详情

相关推荐

LeetCode 55. 跳跃游戏

文章目录55. 跳跃游戏题目解题思路代码实现实现结果 55. 跳跃游戏 题目来源:https://leetcode-cn.com/problems/jump-game 题目 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3 步到达最后一个位置。 示例 2: 输入: [3,2,1,0,4] 输出: false 解释: 无论怎样,你总会到达索引为 3 的位置。

算法-贪心/回溯-跳跃游戏1

算法-贪心/回溯-跳跃游戏1 1 题目概述 1.1 题目出处 https://leetcode-cn.com/problems/jump-game 1.2 题目描述 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: 我们可以先跳 1 步,从位...

迷路剑客个人博客 453

Centos7搭建OpenStack+创建iaas云主机

主要说明在控制节点和计算节点上,通过脚本的形式,安装OpenStack的iaas安装步骤和创建可运行的云主机。提供实施简单、可大规模扩展、丰富、标准统一的云计算管理平台。

weixin_48218106的博客 1万+

算法-贪心/回溯-跳跃游戏2

算法-贪心/回溯-跳跃游戏2 1 题目概述 1.1 题目出处 https://leetcode-cn.com/problems/jump-game-ii 1.2 题目描述 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 你的目标是使用最少的跳跃次数到达数组的最后一个位置。 示例: 输入: [2,3,1,1,4] 输出: 2 解释: 跳到最后一...

迷路剑客个人博客 257

PaddleOCR在医疗票据识别中的实战:从部署到业务字段提取

本文详细介绍了PaddleOCR在医疗票据识别中的实战应用,重点阐述了其离线部署方案与PP-OCRv3模型选型优势。针对医疗票据敏感数据不出本地的合规要求,文章提供了从环境搭建、模型配置到核心字段提取策略的完整流程,并分享了性能优化与系统集成的实践经验,有效解决了医疗票据自动化录入的难题。

weixin_29271053的博客 236

AI影像组学在结直肠癌诊疗中的应用:从特征提取到临床决策

影像组学通过高通量计算从医学影像中提取定量特征,揭示肿瘤内部的微观生物学行为,这些特征反映了纹理异质性、形状不规则度等影像表型。其核心原理在于将图像数据转化为可分析的数字特征,结合机器学习算法进行模式识别,从而实现对疾病状态的精准预测。这一技术的价值在于能够无创、定量地评估肿瘤特性,为精准医疗提供关键支持。在临床实践中,AI驱动的影像组学模型广泛应用于结直肠癌的诊疗全链条,包括肿瘤良恶性鉴别、基因突变预测、治疗反应评估和预后分析等场景。通过整合影像组学特征与临床数据,可以构建预测模型,辅助医生进行更准确的诊

weixin_28295799的博客 409

LeetCode55. 跳跃游戏(java,回溯,动态规划)

1.问题 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 2.解答 方法一:回溯 // 贪婪,每次走尽可能大的步数, // 如果无法到达最后一个位置,走次大的步数; // 直到没有遍历的可能性。 class Solution { public boolean canJump(int[] nums) ...

rosefun96的博客 606

I-Cache 和 D-Cache

I-Cache 和 D-Cache

liuyuanbin9001 7022

Leetcode55. 跳跃游戏--贪心算法,回溯算法

贪心算法局部最优解:每次取最大跳跃步数(取最大覆盖范围),整体最优解:最后得到整体最大覆盖范围,看是否能到终点。 局部最优推出全局最优,找不出反例,试试贪心! class Solution { public: bool canJump(vector<int>& nums) { int cover=0; if (nums.size()==1) return true; for (int i=0; i<=cover;i++){ .

weixin_41811657的博客 271

InsightFace实战:如何在树莓派上部署轻量级人脸识别系统(附完整代码)

本文详细介绍了如何在树莓派上部署基于InsightFace框架的轻量级人脸识别系统。通过硬件选型、环境配置、模型优化(如MobileFaceNet)及完整代码实战,指导开发者构建本地化、低功耗的智能应用,如智能门铃,并提供了性能调优与系统服务化的进阶技巧。

weixin_29043895的博客 351

突破Cloudflare 5秒盾:TLS指纹伪装+Playwright行为模拟,爬虫存活率从35%提至78%

TLS指纹精准识别:Cloudflare会解析客户端的TLS Client Hello包(如SSL版本、密码套件、扩展字段),Python的requests/urllib库的TLS指纹是“黑名单级”,请求一出即被拦截;行为特征检测:静态的浏览器伪装(如User-Agent)已失效,Cloudflare会监控页面加载后的行为(是否有鼠标移动、滚动、点击,行为是否机械);JS环境深度验证:通过WebGL、Canvas、字体渲染、Navigator属性生成浏览器指纹,无头浏览器的默认配置会被瞬间识别;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2360

力扣(19) - 跳跃游戏

给定一个非负整数数组 nums ,你最初位于数组的 第一个下标 。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个下标。 示例 1: 输入:nums = [2,3,1,1,4] 输出:true 解释:可以先跳 1 步,从下标 0 到达下标 1, 然后再从下标 1 跳 3 步到达最后一个下标。 示例 2: 输入:nums = [3,2,1,0,4] 输出:false 解释:无论怎样,总会到达下标为 3 的位置。但该下标的最大跳跃长度是 0 , 所以永远不可能到达最后一个下标。

Touale的博客 929

基于 PCL 的工业盒体点云精准分割

本文提出一种基于PCL点云库的工业盒体点云分割算法,采用由粗到精的分层策略解决传统方法在噪声、稀疏和堆叠场景下的分割问题。算法通过区域生长粗分割、RANSAC平面筛选、球面回溯补全、凹包边界提取和圆柱回溯精分割五大核心模块,充分利用盒体几何先验特征,实现高效精准的分割效果。文章详细阐述了算法流程、参数调优指南及工程化要点,指出该方法相比深度学习具有速度快、鲁棒性强、部署简单的优势。同时分析了算法在倾斜、异形目标上的局限性,并展望了结合深度学习特征的混合模型发展方向。该算法为工业自动化场景中的3D视觉检测提供

weixin_45196569的博客 172

算法:01 贪心、DP、回溯解决 Leetcode 第55题 跳跃游戏

Leetcode 55.跳跃游戏 问题描述:   1、贪心 思想:每一次都找到局部最优解 具体分析: 拿数组 a = [2, 3, 1, 1, 4] 举例 首先,我们必能跳到索引位置0,即 a[0] 的位置,而 a[0] 的最大跳跃长度为 2,则在 a[0] 处、我们可以走 1 步 or 2 步 这时,如果我们可以通过 a[0] 位置直接走到最后一个位置,那么我们一定可以在 从 a[...

echofzoe的博客 1207

开源模型应用落地-qwen模型小试-Qwen3-8B-快速体验(一)

阿里云推出国内首个集成“快思考”与“慢思考”能力的 Qwen3-8B 大语言模型,以80亿参数和 128K 上下文支持,重塑AI应用边界并助力开发者高效部署

以微薄之力,予他人些许温暖. 2万+

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

面试官最爱问的‘贪心 vs 动态规划’:从LeetCode真题看区别与选择

本文深入解析了贪心算法与动态规划在技术面试中的核心区别与应用场景。通过LeetCode经典题目如买卖股票最佳时机和跳跃游戏,详细对比两种算法的时间复杂度、空间复杂度及适用条件,帮助读者掌握选择最优解法的决策框架,提升面试表现。

weixin_30294295的博客 469

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

LeetCode题目55:跳跃游戏【python5种算法贪心/回溯/动态规划/优化贪心/索引哈希映射 详解】

通过5种算法和实际案例详细介绍了跳跃游戏

10年数据\经营分析经验,现任大厂数据分析负责人 2446

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【每日算法】LeetCode 55. 跳跃游戏(贪心算法)

前端开发中,算法能力是进阶关键。本文以LeetCode 55题"跳跃游戏"为例,分析三种解法:1)贪心算法(最优解,O(n)时间),通过维护最远可达位置判断;2)动态规划(O(n²)时间),自底向上记录状态;3)暴力回溯(仅理解用)。类比前端场景如进度条加载、多级菜单展开,推荐贪心算法实现,代码简洁高效。不同解法对比显示贪心算法最适合实际应用,帮助开发者从功能实现者成长为系统设计者。

LYFlied的博客 590

【Leetcode hot 100】55.跳跃游戏

摘要: 55.跳跃游戏要求判断能否从数组起始点跳到终点。最优解法是贪心算法:遍历数组,维护当前能到达的最远位置maxReach。若当前位置在maxReach范围内,更新maxReach;若超出范围则失败;若覆盖终点则成功。时间复杂度O(n),空间O(1)。也可倒序遍历,从终点回溯到起点。动态规划解法(O(n²))效率较低但易于理解。贪心法(正序/倒序)是实际首选,动态规划适合辅助学习。

专注Java和MySQL领域知识分享 833

LeetCode 55跳跃游戏 【动态规划 + 贪心】

55. 跳跃游戏 难度中等631 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3 步到达最后一个位置。 示例 2: 输入: [3,2,1,0,4] 输出: fa...

liuhehe123的博客 754

Leetcode 55. 跳跃游戏

4、在一些问题上,nonlocal声明是必不可少的,尤其是当变量为非类对象时,比如res=int,bool等具有实际内存的变量,必须要在递归函数中声明nonlocal res;后来发现这道题其实是动态规划问题,典型的从子问题可以推到父问题,但是需要注意这道题对于时间和空间复杂度的要求是比较高的,从这也能看出来这道题其实也是个贪心问题。回溯的核心思维其实是遍历所有并且记录路径path,并且当子状态无法返回父状态时,是不需要记录visited的,只需要记录path。回溯的核心是回溯路径也就是path。

普通攻击往后拉的博客 601

hot100 跳跃游戏(55)

本题采用贪心算法(又称“最远可达边界单调扫描法”)解决一维数组可达性判定问题。其核心本质是将原本属于图论连通性或动态规划的状态空间搜索,简化为在单次线性扫描中动态维护与收敛全局最远可达下标边界mx。当前提供的源码实现了在时间复杂度 O(n) 和额外空间复杂度 O(1) 条件下的全局最优检索,最终走向是精准判定初始位置能否跨越所有零值障碍并覆盖最后一个数组下标。

2603_96126046的博客 344

55. 跳跃游戏

题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例1: 输入: [2,3,1,1,4] 输出: true 解释: 从位置 0 到 1 跳 1 步, 然后跳 3 步到达最后一个位置。 示例2: 输入: [3,2,1,0,4] 输出: false 解释: 无论怎样,你总会到...

wchzh2015的博客 165

LeetCode刷题:55. Jump Game 跳跃游戏

LeetCode刷题:55. Jump Game 跳跃游戏 原题链接:https://leetcode.com/problems/jump-game/ Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in th...

梅森上校的博客 业精于勤荒于嬉,形成于思毁于随。 470

LeetCode_贪心算法

记录贪心经典算法题

qq_43563660的博客 918

【贪心算法】leetcode55跳跃游戏贪心算法和动态规划

题目描述 给定一个非负整数数组,你最初位于数组的第一个位置。 数组中的每个元素代表你在该位置可以跳跃的最大长度。 判断你是否能够到达最后一个位置。 示例 1: 输入: [2,3,1,1,4] 输出: true 解释: 我们可以先跳 1 步,从位置 0 到达 位置 1, 然后再从位置 1 跳 3 步到达最后一个位置。 示例 2: 输入: [3,2,1,0,4] 输出: false 解释: 无论怎样,你总会到达索引为 3 的位置。但该位置的最大跳跃长度是 0 , 所以你永远不可能到达最后一个位置。 通过的代码一

qq_38391210的博客 240
上一篇: LeetCode 49. 字母异位词分组(hashmap
下一篇: LeetCode 56. 合并区间(排序
RedemptionC
博客等级 码龄11年 103粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值