Jump Game

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

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.

不断更新能达到的最远范围rch,

如果rch >= n-1,说明到达最后,返回true

否则返回false

class Solution {
public:
bool canJump(int A[], int n) {
int rch = ;
for(int i = ; i <= rch; i ++)
{
rch = max(rch, A[i]+i);
if(rch >= n-)
return true;
}
return false;
}
};

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

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

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

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

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

  3. 【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 + ...

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

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

  5. 【LeetCode】45. Jump Game II

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

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

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

  7. 【leetocode】55. Jump Game

    You are given an integer array nums. You are initially positioned at the array's first index, and ea ...

  8. 【LeetCode】731. My Calendar II 解题报告(Python)

    [LeetCode]731. My Calendar II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...

  9. 【LeetCode】732. My Calendar III解题报告

    [LeetCode]732. My Calendar III解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar ...

随机推荐

  1. 让QT/Embedded支持国际化

    让QT/Embedded支持国际化 环境配置: Qt/Embedded ,在主机和目标板上存放路径都为:/root/qt-embedded-free- Qt/X11 3.3 (主要用到其中的lupda ...

  2. OpenCV学习(28) 轮廓

    OpenCV中可以方便的在一副图像中检测到轮廓,并把这些轮廓画出来.主要用到两个函数:一个是findContours( img, contours0, hierarchy, RETR_TREE, CH ...

  3. [置顶] 一道经典的sql面试题不同的写法

    用一条SQL语句   查询出每门课都大于80分的学生姓名,表( #test)如下:    Name Course Mark 张三 语文 81 张三 数学 75 李四 语文 76 李四 数学 90 王五 ...

  4. [leetcode]Binary Tree Preorder Traversal @ Python

    原题地址:http://oj.leetcode.com/problems/binary-tree-preorder-traversal/ 题意:这题用递归比较简单.应该考察的是使用非递归实现二叉树的先 ...

  5. iOS开发-UIApplication和App启动状态

    UIApplication简单从字面上了解就是应用程序,开发的时候有的时候会根据需要调用其中的方法,看起来不起眼,实际在iOS开发UIApplication提供了iOS程序运行期间的控制和协作工作.每 ...

  6. idea unicode自动转码设置

    idea unicode自动转码设置 File > Settings > Editor > File Encodings 右侧 Properties Files 中 选中 Trans ...

  7. Session 共享(Custom模式)By Memcached(原创)

    1.web.config配置: <machineKey decryptionKey="FD69B2EB9A11E3063518F1932E314E4AA1577BF0B824F369& ...

  8. MVC 之 属性详解

    一.System [AttributeUsage]:指定另一特性类的用法.无法继承此类. [CLSCompliant]:指示程序元素是否符合公共语言规范 (CLS).无法继承此类. [ContextS ...

  9. NSDate 时区转换问题

    一: NSDateFormatter *dateFormater = [[NSDateFormatter alloc]init]; [dateFormater setDateFormat:@" ...

  10. mv命令(转)

    原文:http://www.cnblogs.com/peida/archive/2012/10/27/2743022.html mv命令是move的缩写,可以用来移动文件或者将文件改名(move (r ...