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. PHP DDos的几个防御方法详解

    这类攻击有一个最大的特性,就是上传流量霎时增大,通常流量高达数十以至近百M,将整台效 劳器,以至将整台机柜的宽带堵住,使网站无法运转,而这样的攻击,我们无法从远程处理,一但那个phpshell运转,你 ...

  2. SPOJ7001(SummerTrainingDay04-N 莫比乌斯反演)

    Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...

  3. Linux 安装redis,redis发布订阅,持久化

    安装redis 1.安装redis的方式 -yum (删除这个yum安装的redis,我们只用源码编译安装的) -rpm -源码编译 2.删除原本的redis yum remove redis -y ...

  4. 设计模式原则(7)--Composition&AggregationPrinciple(CARP)--合成&聚合复用原则

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.定义:  要尽量使用合成和聚合,尽量不要使用继承. 2.使用场景: 要正确的选择合成/复用和继承,必须透彻地理 ...

  5. js-ES6学习笔记-let命令

    1.let命令 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. for循环的计数器,就很合适使用let命令. 下面的代码如果使用var ...

  6. 反射和动态加载bean 完成 通用servie

    最近我们部门有个小项目,用来管理这个公司所有项目用到的代码表,例如国家代码.行政区划代码等.这个项目的功能其实很少,就是简单的修改.查询.新增和逻辑删除.但是为每张表都写一套增删改查的页面和一套ser ...

  7. TFS命令行操作

    前言 本文主要介绍如何通过TFS(Team Foundation Server)命令行强制解锁(UnDo)项目成员对项目文件的占用. 正文 在多人同时开发项目的时候,如果遇到项目组成员独占签出文件后未 ...

  8. Redis集群迁移

    1:开发中断程序,登录各个主节点查看key信息 INFO # Keyspace db0:keys,expires,avg_ttl # Keyspace db0:keys,expires,avg_ttl ...

  9. 系统监控工具-glances

    作为运维不仅要时时监控系统,还需要优雅的装13,当别人还在命令的小黑框里敲打那个top命令去查看系统性能的时候,我们带你使用web端监控系统性能 glances 是利用Python语言开发,的监控工具 ...

  10. Interpreting /proc/meminfo and free output for Red Hat Enterprise Linux 5, 6 and 7

    Interpreting /proc/meminfo and free output for Red Hat Enterprise Linux 5, 6 and 7 Solution Verified ...