You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise.

class Solution {
public:
bool canJump(vector<int>& nums) {
int n=nums.size();
int i=0,step=nums[i];
while(i<=step){
step=max(step,i+nums[i]);
if(step>=n-1) break;
i++;
}
return step>=n-1;
}
};

【leetocode】55. Jump Game的更多相关文章

  1. 【LeetCode】55. Jump Game

    Jump Game Given an array of non-negative integers, you are initially positioned at the first index o ...

  2. 【LeetCode】55. Jump Game 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...

  3. 【概率论】5-5:负二项分布(The Negative Binomial Distribution)

    title: [概率论]5-5:负二项分布(The Negative Binomial Distribution) categories: - Mathematic - Probability key ...

  4. 【一天一道LeetCode】#55. Jump Game

    一天一道LeetCode系列 (一)题目 Given an array of non-negative integers, you are initially positioned at the fi ...

  5. 【Leetcode】1340. Jump Game V 【动态规划/记忆性搜索】

    Given an array of integers arr and an integer d. In one step you can jump from index i to index: i + ...

  6. 【LeetCode】45. Jump Game II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...

  7. 【原创】leetCodeOj --- Jump Game II 解题报告

    原题地址: https://oj.leetcode.com/problems/jump-game-ii/ 题目内容: Given an array of non-negative integers, ...

  8. 【LeetCode】45. Jump Game II

    Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...

  9. 【LEETCODE】55、数组分类,适中级别,题目:79、611、950

    第950题,这题我是真的没想到居然会说使用队列去做,大神的答案,拿过来瞻仰一下 package y2019.Algorithm.array; import java.util.HashMap; imp ...

随机推荐

  1. HTML基础强化

    1.如何理解HTML? HTML类似于一份word"文档" 描述文档的"结构" 有区块和大纲 2.对WEB标准的理解? Web标准是由一系列标准组合而成.一个网 ...

  2. DeWeb进阶 :控件开发 --- 1 完成一个纯html的demo

    最近随着DeWeb(以下简称DW)的完善,和群友的应用的深入,已经有网友开始尝试做DeWeb支持控件的开发了! 这太令人兴奋了! 作为DeWeb的开发者,感觉DeWeb的优势之一就是简洁的第三方控件扩 ...

  3. 『学了就忘』Linux基础命令 — 26、帮助命令

    目录 1.man命令 (1)man命令的快捷键 (2)man命令的帮助级别(了解即可) (3)man命令的使用 2.info命令 3.help命令 4.--help选项 1.man命令 man是最常见 ...

  4. spark structured-streaming 最全的使用总结

    一.spark structured-streaming  介绍 我们都知道spark streaming  在v2.4.5 之后 就进入了维护阶段,不再有新的大版本出现,而且 spark strea ...

  5. void * 是什么?

    最近遇到void *的问题无法解决,发现再也无法逃避了(以前都是采取悄悄绕过原则),于是我决定直面它. 在哪遇到了? 线程创建函数pthread_create()的最后一个参数void *arg,嗯? ...

  6. SpringBoot目录文件结构总结(5)

    1.目录 src/main/java :存放java代码 src/main/resources static:存放静态文件,比如css.js.image(访问方式 http://localhost:8 ...

  7. v-html | 数据内容包含元素标签或者样式

    问题 如果我们展示的数据包含元素标签或者样式,我们想展示标签或样式所定义的属性作用,该怎么进行渲染 插值表达式{{}}和v-text指令被直接解析为了字符串元素. <body> <d ...

  8. Navicat15最新版本破解 亲测可用!!!(Navicat Premium 注册出现 No All Pattern Found! File Already Patched)

    1.下载Navicat Premium官网https://www.navicat.com.cn/下载最新版本下载安装 2.本人网盘链接:https://pan.baidu.com/s/1ncSaxId ...

  9. 求求你们了,别再写满屏的 if/ else 了!

    为什么我们写的代码都是 if-else? 程序员想必都经历过这样的场景:刚开始自己写的代码很简洁,逻辑清晰,函数精简,没有一个 if-else,可随着代码逻辑不断完善和业务的瞬息万变:比如需要对入参进 ...

  10. 12组-Alpha冲刺-4/6

    侯钦凯 过去两天完成了哪些任务 完善UI界面,复习考试 展示GitHub当日代码/文档签入记录 接下来的计划 复习考试,准备答辩 还剩下哪些任务 博客和答辩 燃尽图(团队整体) 遇到了哪些困难 在部分 ...