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. .net从网络接口地址获取json,然后解析成对象(二)

    整理代码,这是第二种方法来读取json,然后反序列化成对象的,代码如下: public static Order GetOrderInfo(string _tid, string _orderNo) ...

  2. navigator - 定时器 - event

    1. navigator userAgent: 包含浏览器名称,内核,版本号的字符串 鄙视: 如何判断浏览器名称和版本号 2. 定时器: 2种: 1. 周期性定时器: 什么是: 让程序每隔一段时间间隔 ...

  3. about CSS3

    1. 1.transition 语法:transition:[ transition-property ] || [ transition-duration ] || [ transition-tim ...

  4. Blob CLOB区别

    区别: CLOB :使用char来保存数据.例如xml文件.文章或者较长的文字. BLOB:就是使用二进制保存数据.例如保存位图.图片音乐. 联系:两者可以互相转换.或者直接用lob字段代替两者. 读 ...

  5. libmysqlclient version

    You probably know that the version number of the libmysqlclient.so library has changed from .16 to . ...

  6. Python之入门篇1

    一.安装python解释器 官网: https://www.python.org/downloads/windows/ 自行下载安装,添加环境变量 #测试安装是否成功 windows --> 运 ...

  7. TP5在lnmp环境中不能重写的问题

    说到坑,这个问题困扰了我一两天时间,本地可以,线上环境检查了好久. 基本检查的地方有几个了,首先就是nginx下面的重写配置,这个大家在网上都能搜到,至于定义的变量和配置路径,修改一下即可. 还有就是 ...

  8. IPython:一种交互式计算和开发环境

    IPython基础 可以通过命令行启动IPython,执行任何Python语句,只需将其输入然后回车. Tab键自动完成 在Shell中输入表达式时,只要按下Tab键,当前命名空间中任何与已输入的字符 ...

  9. MES制造执行系统

    mes :  Manufacturing Execution System 制造执行系统 起因:ERP系统和底层设备之间出现了断层. 包括资源管理,生产调度,单元分配,生产跟踪,性能分析,文档管理,人 ...

  10. urllib — URL handling modules

    urllib is a package that collects several modules for working with URLs: •urllib.request for opening ...