Jump Game II
来源:互联网 发布:迅雷 mac 速度0 编辑:程序博客网 时间:2024/06/04 18:25
class Solution {
public:
int jump(vector<int>& nums) {
if(nums.size()==1) return 0;
int maxreach=nums[0];
int step=1;
int start=0,newmax=0;
while(maxreach<nums.size()-1)
{
//newmax = maxreach;
for(int j=start+1;j<=maxreach;j++) //j是,不是从1开始。
{
newmax=max(newmax,nums[j]+j);
}
start=maxreach;
step++;
//maxreach=max(maxreach,newmax);
maxreach=newmax;
}
return step;
}
};
public:
int jump(vector<int>& nums) {
if(nums.size()==1) return 0;
int maxreach=nums[0];
int step=1;
int start=0,newmax=0;
while(maxreach<nums.size()-1)
{
//newmax = maxreach;
for(int j=start+1;j<=maxreach;j++) //j是,不是从1开始。
{
newmax=max(newmax,nums[j]+j);
}
start=maxreach;
step++;
//maxreach=max(maxreach,newmax);
maxreach=newmax;
}
return step;
}
};
0 0
- Jump Game &Jump Game II
- Jump Game/Jump Game II
- LeetCode: Jump Game II
- LeetCode Jump Game II
- LeetCode: Jump Game II
- [Leetcode] Jump Game II
- [LeetCode] Jump Game II
- [Leetcode] Jump Game ii
- leetcode Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- leetcode Jump Game II
- [LeetCode]Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- Spring Boot开发之流水无情(二)
- (转)ueditor使用webuploader以后多图上传后顺序乱掉问题解决方法
- Dalvik & ART
- LaTeX beamer制作中插图的经历
- android:MAT内存分析工具的使用
- Jump Game II
- input 有效数字
- xCode6制作动态及静态Framework
- 后缀为 ashx 与 axd 的文件区别浅析
- Dependency Walker,探寻DLL和EXE文件
- jar包中相对路径处理
- Unity3D引用dll打包发布的问题及解决
- Win7下安装与配置PHP环境(二)
- openssl在java端的加解密和签名验证