跳跃游戏 II-LintCode
来源:互联网 发布:关宁锦防线 知乎 编辑:程序博客网 时间:2024/05/18 02:14
给出一个非负整数数组,你最初定位在数组的第一个位置。
数组中的每个元素代表你在那个位置可以跳跃的最大长度。
你的目标是使用最少的跳跃次数到达数组的最后一个位置。
样例:
给出数组A = [2,3,1,1,4],最少到达数组最后一个位置的跳跃次数是2(从数组下标0跳一步到数组下标1,然后跳3步到数组的最后一个位置,一共跳跃2次)
#ifndef C117_H#define C117_H#include<iostream>#include<vector>using namespace std;#include<algorithm>class Solution {public: /** * @param A: A list of lists of integers * @return: An integer */ int jump(vector<int> A) { // wirte your code here int len = A.size(); vector<int> v(len, 0); for (int i = 1; i < len; ++i) { for (int j = 0; j < i; ++j) { if (j + A[j] >= i) { v[i] = v[j] + 1; break; } } } return v[len - 1]; }};#endif
阅读全文
0 0
- LintCode:跳跃游戏 II
- [Lintcode]跳跃游戏 II
- 跳跃游戏 II-LintCode
- lintcode --跳跃游戏II
- lintcode-跳跃游戏II-117
- [LintCode] 跳跃游戏II Jump Game II
- LintCode-跳跃游戏
- lintcode-跳跃游戏-116
- Lintcode—跳跃游戏
- [LintCode] 跳跃游戏
- lintcode ----跳跃游戏
- LintCode:跳跃游戏
- LintCode : 跳跃游戏
- LintCode 116-跳跃游戏
- LintCode 跳跃游戏 解答
- LintCode : 跳跃游戏
- 跳跃游戏-LintCode
- lintcode--跳跃游戏
- TextView工作笔记
- eclipse一些简单设置
- 455. Assign Cookies
- shiro 异常总结
- PHP5升级PHP7-永久环境变量设置
- 跳跃游戏 II-LintCode
- MFC之底层窗口创建
- Elasticsearch安装及自动同步mysql数据库数据
- android 开发规范1
- Eclipse打开C/C++文件报错问题
- 启动多个MySQL实例作为Windows服务
- java 类加载顺序
- 深度学习:Sigmoid函数与损失函数求导
- 记腾讯互娱网站布局(1)