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.

注意这里的每个位上的数是可以跳跃的最大长度,应该使用贪心策略,看了别人的实现,代码如下,以后好好思考下:

 class Solution {
public:
bool canJump(vector<int>& nums) {
int sz = nums.size();
if(!sz) return false;
int left = nums[];
for(int i = ; i < sz; ++i)
if(left > ){
left--;
left = max(left, nums[i]);
}else return false;
return true;
}
};

LeetCode OJ:Jump Game(跳跃游戏)的更多相关文章

  1. [LeetCode] 55. Jump Game 跳跃游戏

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

  2. [LeetCode] Jump Game 跳跃游戏

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

  3. 【LeetCode每天一题】Jump Game(跳跃游戏)

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

  4. 055 Jump Game 跳跃游戏

    给定一个非负整数数组,您最初位于数组的第一个索引处.数组中的每个元素表示您在该位置的最大跳跃长度.确定是否能够到达最后一个索引.示例:A = [2,3,1,1,4],返回 true.A = [3,2, ...

  5. Leetcode55. Jump Game跳跃游戏

    给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...

  6. leetcode刷题-55跳跃游戏

    题目 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 思路 贪心算法:记录每一个位置能够跳跃到的最远距离,如果 ...

  7. [LeetCode] 45. Jump Game II 跳跃游戏 II

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

  8. LeetCode(45): 跳跃游戏 II

    Hard! 题目描述: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 示例: 输入: [ ...

  9. 【LeetCode每天一题】Jump Game II(跳跃游戏II)

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

  10. 力扣Leetcode 45. 跳跃游戏 II - 贪心思想

    这题是 55.跳跃游戏的升级版 力扣Leetcode 55. 跳跃游戏 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃 ...

随机推荐

  1. 亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]

    亿能测试大讲堂 - YY在线课程[ 测试人员需要掌握的Shell脚本编程 ]http://automationqa.com/forum.php?mod=viewthread&tid=2453& ...

  2. shiro的Realm

    public class UserRealm extends AuthorizingRealm { private UserService userService = new UserServiceI ...

  3. 谁说程序员不懂爱情【Her】

    2014.8.17日 我和我女朋友恋爱两周年的日子.走到今天很不容易,我很珍惜. 就想趁这机会,尽自己能力做一个特别的礼物. 这款应用两周前就开始计划了.也熬了几个晚上.接触wp开发时间不长,第一款应 ...

  4. QT5.6.0 鼠标支持

    QT5用QPA换了QWS之后,USB鼠标就不知道怎么支持,网上搜啊搜,各种尝试,终于可以了. export TSLIB_ROOT=/mnt/sdcard/tslib export TSLIB_PLUG ...

  5. What is CRC and how does it works?

    What is CRC and how does it works? CRC errors refer to Layer 1 or 2 issues. Two things you should ch ...

  6. Linux:redhat6.5使用yum时提示需要注册问题解决方案

    Linux:redhat6.5使用yum时提示需要注册问题解决方案 一.问题 新安装了redhat6.5.安装后,登录系统,使用yum时候.提示: This system is not registe ...

  7. 20165101刘天野 2018-2019-2《网络对抗技术》Exp3 免杀原理与实践

    20165101刘天野 2018-2019-2<网络对抗技术>Exp3 免杀原理与实践 1. 实践内容 1.1 正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil- ...

  8. Django QuerySet API

    https://docs.djangoproject.com/en/2.1/ref/models/querysets/

  9. cocoa应用程序中NSStatusItem的使用

    mac上的应用程序除了左上方会有菜单之外,在屏幕的右上方也会有一个图标样的菜单,这个类似于windows上右下角的system tray. 本文讲述如何给自己的应用程序添加一个system tray( ...

  10. 简单介绍java Enumeration(转)

    Enumeration接口 Enumeration接口本身不是一个数据结构.但是,对其他数据结构非常重要. Enumeration接口定义了从一个数据结构得到连续数据的手段.例如,Enumeratio ...