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. python数据结构详解

    Python中常见的数据结构可以统称为容器(container).序列(如列表和元组).映射(如字典)以及集合(set)是三类主要的容器. 一.序列(列表.元组和字符串) 序列中的每个元素都有自己的编 ...

  2. VB.NET and C# 差异

    VB.NET Program Structure C# Imports System Namespace Hello    Class HelloWorld       Overloads Share ...

  3. 进入快速通道的委托(深入理解c#)

    1.方法组:所有的名称相同的重载方法合在一起就成为一个方法组. 2.协变性和逆变性: 协变性指的是——泛型类型参数可以从一个派生类隐式转化为基类. 逆变性指的是——泛型类型参数可以从一个基类隐式转化为 ...

  4. Quartz(强大的定时器)

    1.关于Quartz的配置文件说明 # # Quartz会优先读取项目下我们自定义这个quartz.properties配置文件 否则会去读取quartzjar包下org.quatrz包# 下面的那个 ...

  5. springboot+websocket示例

    1.新建maven工程 工程结构如下: 完整的pom.xml如下: <?xml version="1.0" encoding="UTF-8"?> & ...

  6. error C2065: 'IDD_DIALOG1' : undeclared identifier

    添加资源文件 #include "resource.h"

  7. 解决Linux下IDEA无法使用ibus输入法的问题和tip乱码

    一:可以先按网上的配置/etc/profile里的输入法的一些参数,我是先配置了这些参数的,但是输入法还是没用,后来一直没管它了,今天用了一些方式可以了但不敢保证不需要先配置那些参数: 二:情况:开启 ...

  8. [转]MySQL源码:Range和Ref优化的成本评估

    MySQL源码:Range和Ref优化的成本评估 原文链接:http://www.orczhou.com/index.php/2012/12/mysql-source-code-optimizer-r ...

  9. python_day1_python第一个程序 hello world

    Python 第一个程序 1)安装好python后,cmd进入DOS下,直接输入python Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06 ...

  10. dom4j 通过 org.dom4j.DocumentFactory 设置命名空间来支持 带namespace 的 xpath

    测试文件 test.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/ ...