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.

Example 1:

Input: [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.

Example 2:

Input: [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum   jump length is 0, which makes it impossible to reach the last index.
想法:动态规划方式,按照如下方式:
1、最后一步:假设在索引i的地方,能够到达索引n-1,那么需要满足条件(1)青蛙能够落在索引i(2)i+array[i]>n-1
2、状态转移表达式:f[j] = (0=<i<j)(f[i]&&i+f[i]>j)
3、边界条件:f[0]=true
4、计算顺序
class Solution {
public:
    bool canJump(vector<int>& nums) {
         == nums.size())
            return false;
        bool result[nums.size()] ;
        result[] = true;
//从第一块石头开始
         ; i < nums.size() ; i++){
            result[i] = false;
            //遍历石头i之前的所有石头,判断那一块能够落在石头i上
             ; j < i ; j++){
                if(result[j] && j + nums[j] >= i){
                    result[i] = true;
                }
            }
        }
        ];
    }

};

leetcode55—Jump Game的更多相关文章

  1. [array] leetcode-55. Jump Game - Medium

    leetcode-55. Jump Game - Medium descrition Given an array of non-negative integers, you are initiall ...

  2. [LeetCode55]Jump Game

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

  3. leetcode-55. Jump Game · Array

    题面 这个题面挺简单的,不难理解.给定非负数组,每一个元素都可以看作是一个格子.其中每一个元素值都代表当前可跳跃的格子数,判断是否可以到达最后的格子. 样例 Input: [2,3,1,1,4] Ou ...

  4. Leetcode55. Jump Game跳跃游戏

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

  5. [Swift]LeetCode55. 跳跃游戏 | Jump Game

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

  6. [LeetCode] Frog Jump 青蛙过河

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  7. [LeetCode] Jump Game 跳跃游戏

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

  8. [LeetCode] Jump Game II 跳跃游戏之二

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

  9. Leetcode 45. Jump Game II

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

随机推荐

  1. zookeeper 知识点汇总

    目录 Zookeeper 是什么 Zookeeper 树状模型 Zookeeper 集群结构 如何使用 ZooKeeper 运行 Zookeeper 步骤1 修改 ZooKeeper 配置文件 步骤 ...

  2. Pupu(hdu3003)数论

    Pupu Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. shell_语法

    1.运算符: 1.基本语法:$((运算式))或$[运算式] 2.expr + n // 注意运算符中间有空格 再用expr时要加 ` ` 号,* 号加转义字符\  \* ,表示乘 2.判断语句 [ c ...

  4. xshell提示采购解决方法

    参考http://blog.csdn.net/longgeaisisi/article/details/78637179

  5. 学习html/css基础的重点笔记

    1.权重问题 内联样式表 > id选择符 > class选择符 > 类型选择符(所有html标签名称) 内联样式表 > 内部样式表.外部样式表 内部样式表.外部样式表的权重与书 ...

  6. js 微信支付

    引入 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0. ...

  7. 8.1、包,__init__.py,

    包: 为了组织好模块,将多个模块组合为一个包,所以包用于存放python模块 包通常是一个文件夹,当文件夹当作包使用时,文件夹需要包含__init__.py文件 __init__.py的内容可以为空, ...

  8. python subprocess pipe 实时输出日志

    * test11.py import time print "1" time.sleep(2) print "1" time.sleep(2) print &q ...

  9. Mac日常使用问题

    问题一: macbook如何关闭safari左侧书签栏? 方法1: 快捷键:control+command+1键 办法2: 把光标移到safari顶部, 菜单单出来后, 选择view-->sho ...

  10. imei和imsi

    imei.imsi是大部分应用自动采集的设备信息,Android中需要在MINIFEST声明权限,6.0以上手机还需要用户显示授权才可以正常获取.这两个标识有什么区别.联系?为什么应用这么执着于采集这 ...