LintCode 跳跃游戏 解答
来源:互联网 发布:python 前端框架 编辑:程序博客网 时间:2024/05/18 01:54
跳跃游戏
给出一个非负整数数组,你最初定位在数组的第一个位置。
数组中的每个元素代表你在那个位置可以跳跃的最大长度。
判断你是否能到达数组的最后一个位置。
注意事项
这个问题有两个方法,一个是贪心
和 动态规划
。
贪心
方法时间复杂度为O(N)
。
动态规划
方法的时间复杂度为为O(n^2)
。
我们手动设置小型数据集,使大家阔以通过测试的两种方式。这仅仅是为了让大家学会如何使用动态规划的方式解决此问题。如果您用动态规划的方式完成它,你可以尝试贪心法,以使其再次通过一次。
样例
A = [2,3,1,1,4],返回 true.
A = [3,2,1,0,4],返回 false.
class Solution {public: /** * @param A: A list of integers * @return: The boolean answer */ bool func(vector<int> A, int i, int size){if (i >= size - 1)return true;int t = A[i];while (t > 0){if (func(A, t + i, size))return true;t--;}return false;}bool canJump(vector<int> A) {// write you code hereint size = A.size();int i = 0;return func(A, i, size);}};
0 0
- LintCode 跳跃游戏 解答
- LintCode-跳跃游戏
- lintcode-跳跃游戏-116
- Lintcode—跳跃游戏
- [LintCode] 跳跃游戏
- lintcode ----跳跃游戏
- LintCode:跳跃游戏
- LintCode:跳跃游戏 II
- [Lintcode]跳跃游戏 II
- LintCode : 跳跃游戏
- LintCode 116-跳跃游戏
- LintCode : 跳跃游戏
- 跳跃游戏-LintCode
- 跳跃游戏 II-LintCode
- lintcode--跳跃游戏
- lintcode --跳跃游戏II
- Lintcode 跳跃游戏
- [Lintcode] #116 跳跃游戏
- 面试题(ASP.NET应用开发)
- 【Linux】解决ubuntu14.04下升级系统之后搜狗输入法不能用的问题
- LeetCode刷题【Array】 Search in Rotated Sorted Array II
- FIFO IP核在DSP与ARM之间做数据缓存
- 自定义校验器实例
- LintCode 跳跃游戏 解答
- java 获取邮件数据
- Objective-C如何自己实现一个基于数组下标的属性访问模式
- Python 连接 百度语音 服务
- 常用数据库连接池的配置
- Robot Framework安装部署详细教程(Windows7 64位)
- MongoDB常用命令以及数据类型
- RTP协议分析
- android.content.res.Resources$NotFoundException: String resource ID