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. SSM整合的pom.xml依赖

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  2. Mycat入门配置_读写分离配置

    1.Mycat的分片 两台数据库服务器: 192.168.80.11 192.168.80.4 操作系统版本环境:centos6.5 数据库版本:5.6 mycat版本:1.4 release 数据库 ...

  3. [翻译]C# BAD PRACTICES: Learn how to make a good code by bad example---C#:如何将坏的代码重新编译为好的代码

    自己的前言说明: 本文原作者:Radoslaw Sadowski,原文链接为:C# BAD PRACTICES: Learn how to make a good code by bad exampl ...

  4. 绘图:Matplotlib

    用于绘制一些数据图,同学推荐的,挺好用.非常好的官网文档:http://matplotlib.org/contents.html 0. 安装 可以直接pip install,还有一些依赖就按照提示来吧 ...

  5. centos7下docker发布第一个微服务应用(Eureka)

    1.在windows下打包 微服务应用通过maven进行打包,在项目的pom.xml执行mvn clean package,或者直接通过idea或者eclipse进行maven打包 之上操作将在项目的 ...

  6. Unable to open debugger port (127.0.0.1:63777): java.net.BindException "Address

    困扰了我好久,试过删掉taget文件夹rebuild,不删除Tomcat Server配置手动修改端口号也不行,试过杀掉java进程和重启机器,但是就是没效果. 解决: 删除Tomcat Server ...

  7. BZOJ3108 [cqoi2013]图的逆变换

    Description 定义一个图的变换:对于一个有向图\(G=(V, E)\),建立一个新的有向图: \(V'=\{v_e|e \in E\}\),\(E'=\{(v_b, v_e)|b=(u,v) ...

  8. javascript: 数组详细操作方法及解析合集(9个改变8个不变12个遍历)

    改变原数组的方法(9个): 1 2 3 4 5 let a = [1,2,3]; ES5: a.pop()/ a.shift()/ a.push()/ a.unshift()/ a.reverse() ...

  9. 基于 Web 的 Go 语言 IDE - Wide 1.5.2 发布!

    这个版本由热心的开源贡献者加入了韩语支持,欢迎各位 gophers 加入到 Wide 的开源开发中.另外,这个版本还改进了 Playground,使其更稳定和易用.目前黑客派社区已经支持嵌入 Wide ...

  10. 活字格Web应用平台学习笔记4 - 添加记录

    今天继续学习活字格基础教程,目标是创建一个页面,增加记录. 开始之前,系统会自动把上一次的工程文件加载进来. 这是做好后的样子. 我点添加员工的超链接: 先后加了2条员工的信息进来. 不错,设计界面是 ...