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. Java系统和PHP系统相互调用

    一.HTTP JSON方式的缺点 JSON序列化效率低 多语言服务治理功能低 二.关于RPC框架 RPC 框架大致分为两类,一种是偏重服务治理,另一种侧重跨语言调用 2.1 服务治理型 特点 功能丰富 ...

  2. POJ3281(KB11-B 最大流)

    Dining Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19170   Accepted: 8554 Descripti ...

  3. 【读书笔记】iOS-iOS6 Passbook应用开发

    Passbook 是iOS6的新功能,只能在iPhone和iPod touch设备中使用,它可以帮助管理商家发放的电子会员卡,积分卡,优惠券等. 一,Passbook 与 Pass. Passbook ...

  4. 《Spring实战》-- 'cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element' 错误的解决办法

    在Eclipse中新建了一个maven项目学习Spring,在 service.xml 中配置 Spring,想要学习'面向切面的Spring',service.xml 内容如下: <beans ...

  5. ActiveReports 报表应用教程 (12)---交互式报表之贯穿钻取

    在葡萄城ActiveReports报表中提供强大的数据分析能力,您可以通过图表.表格.图片.列表.波形图等控件来实现数据的贯穿钻取,在一级报表中可以通过鼠标点击来钻取更为详细的数据. 本文展示的是20 ...

  6. Debian 常用命令

    换源 用中科大的比较快 deb http://mirrors.ustc.edu.cn/debian jessie main contrib non-free deb-src http://mirror ...

  7. Prometheus Node_exporter 详解

    Basic CPU / Mem / Disk Info https://www.cnblogs.com/qianyuliang/p/10479515.html Basic CPU / Mem / Di ...

  8. Saltstack安装配置过程

    一.安装配置 1.服务器配置情况 三台服务器,均需要关闭iptables和selinux(否则salt执行指令无效) master: 192.168.60.139 centos slave: 192. ...

  9. 谨慎使用MyBatis自动生成Where语句

    最近监控到类似这样一个慢查询: select XX_time from XXOrderInfo WHERE ( OrderId is not null and OrderId = N'xxxx') x ...

  10. 转:C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、Sort)

    C#常用的集合类型(ArrayList类.Stack类.Queue类.Hashtable类.Sort) .ArrayList类 ArrayList类主要用于对一个数组中的元素进行各种处理.在Array ...