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.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.

 class Solution {
public:
bool canJump(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(==n) return true;
if(==n) return false; int position = ; while(position != (n-)){
if( == A[position])
return false; position += A[position];
if(position >=n)
return true;
} return true;
}
};

我的答案

思路:这道题由于说明了是non-negative integer,唯一到不了终点的情况就是踩到了值为0的点,不能往后走了。总感觉这道题目有问题,如果最后一步迈的特别大,以至于超过了数组的最大脚标,按online judge的意思是可以算作到达的,我原本理解成为了必须正好踩到最后一个位置上才算是到达~总觉得题目有点问题。

[leetcode.com]算法题目 - Jump Game的更多相关文章

  1. [leetcode.com]算法题目 - Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  2. [leetcode.com]算法题目 - Maximum Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  3. [leetcode.com]算法题目 - Gray Code

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  4. [leetcode.com]算法题目 - Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  5. [leetcode.com]算法题目 - Triangle

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  6. [leetcode.com]算法题目 - Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  7. [leetcode.com]算法题目 - Sqrt(x)

    Implement int sqrt(int x). Compute and return the square root of x. class Solution { public: int sqr ...

  8. [leetcode.com]算法题目 - Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  9. [leetcode.com]算法题目 - Pow(x, n)

    Implement pow(x, n). class Solution { public: double pow(double x, int n) { // Start typing your C/C ...

随机推荐

  1. sql复杂查询

    内连接 左外连接 Left Outer Join On  ,无论右边是否匹配到,左边的数据都在 右外连接 Right Outer Join On ,无论左边是否匹配到,右边的数据都在 子查询: 将一个 ...

  2. HDU - 5658

    题意:给你一个字符串,给你Q次询问,每一次问你从l-r里有多少个回文串. 思路:len很小,所以直接遍历区间求就好了. /* gyt Live up to every day */ #include& ...

  3. ubuntu下安装/卸载vmware虚拟机

    1.下载vmware(官网下载试用版,试用版输入序列号后即为专业版,序列号网上搜,很多) 2.下载后安装(命令行) 1)cd进你下载的位置 1.1)下载的文件名字为:VMware-Workstatio ...

  4. 通过http.client解析url返回的数据时为什么中文变成了unicode码

    今天在解析json数据的时候得到了一堆这样的数据:{"errNum":0,"errMsg":"success","retData& ...

  5. 2019.01.17 bzoj1854: [Scoi2010]游戏(二分图匹配)

    传送门 二分图匹配菜题. 题意:nnn个二元组(xi,yi)(x_i,y_i)(xi​,yi​),每个二元组可以选一个数总共nnn个数aia_iai​,问将aia_iai​排好序之后从111开始最多可 ...

  6. 2018.10.26 NOIP模拟 图(最小生成树+线段树合并)

    传送门 首先最开始说的那个一条路径的权值就是想告诉你两个点之间的贡献就是瓶颈边的权值. 那么肯定要用最小生成树算法. 于是我考场上想了30min+30min+30min+的树形dpdpdp 发现转移是 ...

  7. $.cookie is not a function的错误原因

    网上说的原因是:“手残导入2次jquery库文件 ” 是的,就是这个原因.引入了两次jquery.js

  8. IntelliJ IDEA 2017版 Spring5 java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.<init>([Ljava/lang/Object;)V

    错误是java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.<init>([Ljava/lang/ ...

  9. i2c_client的生成

    网上很多文档都是介绍源码,包括i2c_client结构体的源码都有贴出,看上去似乎需要手动写该结构体,但实际上,i2c_client的生成是用如下方法. \arch\arm\mach-omap2/bo ...

  10. dir命令详解

    dir命令:DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]  [/O[[:]sortorder]] ...