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. 前m大的数(hdu1280)

    前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  2. Spring全家桶系列–SpringBoot与Mybatis结合

    //本文作者:cuifuan Mybatis 是一个持久层ORM框架,负责Java与数据库数据交互,也可以简易理解为中介,相对于它,还有个中介是hibernate,不过在mybatis中sql语句的灵 ...

  3. HDU1203(01背包)

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. apicloud 第一篇

    最近公司需要开发一款app,说实话,之前也只是对Android有过一部分的了解,ios基本上都毛都不知道,所以作为小公司的我们经过商议决定使用apicloud,虽然用户体验不如原生的好,但谁叫我们穷, ...

  5. windows环境下IP多访问

    1.E:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf 添加: <VirtualHost *:80> Server ...

  6. CentOS7上搭建LDAP-PDC并且将windows 2008 R2加入LDAP-PDC域

    由于测试原因,要涉及到将windows机器加入到ldap域,所以查看各种文档进行ldap-pdc域的搭建,并成功将windows 2008r2加入到ldap-pdc域中.下面简单记录一下搭建过程 Li ...

  7. SD从零开始25-28

    SD从零开始25 装运的组织单元(Organizational Units in Shipping) 组织结构-后勤Organizational Structure-Logistics Plant在后 ...

  8. 判断exe是64位还是32位

    右击exe属性,查看兼容模式. 如果有windwos vista之前的版本则为32位的,如下图: 如果没有windwos vista之前的版本则为64位的,如下图:

  9. LeetCode题解之 Odd Even Linked List

    1.题目描述 2.问题分析 将链表拆分成两个,奇数节点形成一个链表,偶数节点形成另外一个链表,最后将偶数节点链表加在奇数节点链表后面. 3.代码 ListNode* oddEvenList(ListN ...

  10. Win10命令行激活 & 电脑组装

    系统激活: 1. 管理员身份运行 cmd 2. slmgr.vbs /upk                                                              ...