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. 火狐 debug 看向后台传递的信息

    自己做前端和后台开发,最重要的是数据交换,知道了数据是怎么传的,传到哪里,传的什么,就能很容易的开发. 火狐看传递参数的信息在debug里面,详情如图: 我的后台的C# 的webservice,接收起 ...

  2. python - package - bs4 - 美味汤

    Beautiful Soup 3 only works on Python 2.x, but Beautiful Soup 4 also works on Python 3.x. 你可能在寻找 Bea ...

  3. JDBC连接MySql,配置url报错

    使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one ...

  4. CSS-背景-渐变-文本格式化

    1.背景 1.背景色 属性:background-color 取值:合法的颜色值 注意:背景颜色和背景图片默认都从边框位置处开始填充 2.背景图片 属性:background-image 取值:url ...

  5. normalized

    共同点:实现规范化,让一个向量保持相同的方向,但它的长度为1.0,如果这个向量太小而不能被规范化,一个零向量将会被返回. 不同点:Vector3.normalized的作特点是当前向量是不改变的并且返 ...

  6. 45.UITableView去除分割线

    1.去除所有的分割线 table.separatorStyle = UITableViewCellSelectionStyleNone; 2.去除指定某一行的分割线 cell.separatorIns ...

  7. Jetty 9的使用

    参考来源:https://www.cnblogs.com/empireghost/p/3522834.html

  8. 解决mysql默认的8小时自动断开连接

    语言:javaEE 框架:spring mvc+spring+mybatis 数据库:mysql8 WEB服务器:tomcat8 背景: 在试运营阶段发现发生“连接超时”异常 抛出异常: Cause: ...

  9. hadoop hive组件介绍及常用cli命令

    Hive架构图 Hive产生原因 1 关系型数据库以产生多年sql成熟 2 简化开发降低成本 3 java成员可编写udf函数 Hive是什么 Hive是基于hadoop的一个数据库工具,使用Hql作 ...

  10. js 匿名函数 用法

    JS执行顺序为从上到下 先声明存储匿名函数的变量放在JS文件中 <script src="/Scripts/niming.js" type="text/javasc ...