leetcode之jump game
来源:互联网 发布:sql怎么备份数据库 编辑:程序博客网 时间:2024/05/29 07:38
题目:
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(vector<int>& nums) { int limit = nums[0]; int size = nums.size(); int pos = 0; while(pos < size && pos <= limit) { pos++; if(pos <= limit && nums[pos] + pos > limit) limit = nums[pos] + pos; } return (limit >= size - 1); }};
0 0
- LeetCode 之 Jump Game
- leetcode之Jump Game
- leetcode 之 Jump Game
- LeetCode之Jump Game
- Leetcode 之 Jump Game
- leetcode之jump game
- leetcode之Jump Game
- 【Leetcode】之 Jump Game
- leetcode之Jump Game && Jump Game II
- Leetcode之Jump Game & Jump Game II
- LeetCode之Jump Game II
- 【Leetcode】之Jump Game II
- leetcode之jump game II
- Leetcode之Jump Game问题
- LeetCode 之 Jump Game(贪心算法)
- LeetCode第45之 Jump Game II
- LeetCode进阶之路( Jump Game)
- Leetcode之Jump Game II 问题
- 网易2016研发题 [编程题] 小易的升级之路
- linux 学习记录
- setjmp()、longjmp() Linux Exception Handling/Error Handling、no-local goto
- 如何用Editplus编译运行Java
- 网易校招笔试题 炮台攻击
- leetcode之jump game
- C++接口定义及实现举例
- 机器学习从入门到精通-精选
- java学习(二)数据类型
- MSA镜像文档
- PhpStorm常用快捷键
- 51nod 1087 1 10 100 1000
- GVIM中文编码出现乱码的解决方案
- python logging 日志输出 学习笔记 时间格式化