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基础-3

    图像标签(<img>)和源属性(Src) 在 HTML 中,图像由 <img> 标签定义. <img> 是空标签,意思是说,它只包含属性,并且没有闭合标签. 要在页 ...

  2. PHP笔记2__变量/字符串/类型转换/常量/,,

    <?php //可变变量 $a = "ok"; $$a = "fine"; $$$a = "er"; echo $ok; echo & ...

  3. Oracle SQL注入 总结

    0x00 Oracle基础 Oracle 基本使用 什么是Oracle数据库? Oracle公司目前是世界上最大的软件提供商之一,与它并列的还有 Microsoft与 Adode.并且随着 Oracl ...

  4. Java多线程之Atomic:原子变量与原子类

    Atomic简介 ​ Atomic包是java.util.concurrent下的另一个专门为线程安全设计的Java包,包含多个原子操作类这个包里面提供了一组原子变量类. ​ 其基本的特性就是在多线程 ...

  5. 痞子衡嵌入式:在IAR开发环境下RT-Thread工程函数重定向失效分析

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是在IAR开发环境下RT-Thread工程函数重定向失效分析. 痞子衡旧文 <在IAR下将关键函数重定向到RAM中执行的方法> ...

  6. Python基础(作用域)

    def _private_1(name): return 'Hello, %s' % name def _private_2(name): return 'Hi, %s' % name def gre ...

  7. python爬取豆瓣电影第一页数据and使用with open() as读写文件

    # _*_ coding : utf-8 _*_ # @Time : 2021/11/2 9:58 # @Author : 秋泊酱 # @File : 获取豆瓣电影第一页 # @Project : 爬 ...

  8. web页面自动化总结。selenium

    web自动化测试终篇:总结我理解的ui自动化,整理归纳: https://blog.csdn.net/CCGGAAG/article/details/89669592 web页面自动化知识点 1.we ...

  9. Spring Aop面向切面编程&&自动注入

    1.面向切面编程 在程序原有纵向执行流程中,针对某一个或某一些方法添加通知,形成横切面的过程叫做面向切面编程 2.常用概念 原有功能:切点,pointcut 前置通知:在切点之前执行的功能,befor ...

  10. [loj3246]Cave Paintings

    题中所给的判定条件似乎比较神奇,那么用严谨的话来说就是对于两个格子(x,y)和(x',y'),如果满足:1.$x\le x'$:2.从(x,y)通过x,x+1,--,n行,允许向四个方向走,不允许经过 ...