问题叙述性说明:

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) {
if (n < 1)
return false;
int max_step, i, tmp;
max_step = tmp = 0;
for (i = 0; i < n; i++) {
if (A[i] > max_step)
max_step = A[i];
if ((tmp = max_step + i) == n-1 || tmp > n-1)
return true;
if (max_step == 0)
return false;
max_step--;
}
}
};

版权声明:本文博主原创文章,博客,未经同意不得转载。

最新文章

  1. mac下限速
  2. log4net使用(winform)
  3. OpenGL 简介
  4. Error Dropping Database (Can&#39;t rmdir &#39;.test\&#39;, errno: 17)
  5. 对struts2的基本知识和环境的搭建(配图解)
  6. Java程序员25个必备的Eclipse插件
  7. cmstop传递什么控制器和方法---就实例化该控制器
  8. 移动端1px 边框完整方案(四个方向)
  9. 【转】sed命令n,N,d,D,p,P,h,H,g,G,x解析
  10. javascript语法之Date对象与小案例
  11. linux中的find命令常用场景
  12. RDD的概念与创建
  13. LeetCode算法题-Best Time to Buy and Sell Stock
  14. JVM系列2:垃圾收集器与内存分配策略
  15. 实战:阿里巴巴 DevOps 转型后的运维平台建设
  16. python QT 编程之路
  17. jmeter-如何在JDBC Request中添加多条语句执行
  18. (转)权威支持: 选择正确的 WebSphere 诊断工具
  19. su命令cannot set groups: Operation not permitted的解决方法
  20. Openfire更服务器名称后报Found RSA certificate that is not valid for the server domain的解决方法

热门文章

  1. SetFocus、SetCapture和SetActiveView的区别
  2. hdu1569find the safest road(floyd变形求最大安全值)
  3. 【android】禁止Edittext弹出软键盘而且使光标正常显示
  4. liGDX life_cycle (生命周期)
  5. TWinControl的消息覆盖函数大全(41个WM_函数和31个CM_函数,它的WndProc就处理鼠标(转发)、键盘(取消拖动)、焦点、和WM_NCHITTEST一共4类消息)
  6. 【linux驱动分析】之dm9000驱动分析(六):dm9000_init和dm9000_probe的实现
  7. Android 实现环形进度按钮circular-progress-button
  8. JavaScript 中的事件类型4(读书笔记思维导图)
  9. 轻松学习之Linux教程一 ubuntu14.04+windows双系统安装
  10. android--手机桌面添加网址链接图标(解决方式)