jump game
来源:互联网 发布:网络渗透攻击 编辑:程序博客网 时间:2024/06/05 06:41
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
.
思路:
刚开始动态规划,超时
参考他人的代码,其思路主要为用一个变量保存能到达的最远的距离。
bool canJump(int A[], int n) {
if(A==NULL || n<=0)
{
return false;
}
int max_dis=A[0];
for(int i=0; i<=min(max_dis,n-1); ++i)
{
max_dis = max(max_dis,i+A[i]);
}
return max_dis >= (n-1);
}
0 0
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- 第2次实验——算法基本功 与 综合思考
- ubuntu 12.04 vim安装taglist、ctags和NERDTree
- Android常用计量单位(Dimension)的介绍(px,in,mm,pt,dp,dip,sp)
- Eclipse 字体设置
- 私人使用地方
- jump game
- C语言拾遗:公有、私有和受保护的继承--《C++ primer》笔记
- ios和mac开发 学习资料
- PalindromePartitioning II
- 本地Yum软件源安装Cloudera Manager 5
- java 抽象类与接口的使用
- 为SUSE Linux添加软件安装源的方法
- metalink mos介绍
- JS随录-2