Leetcode之Jump Game II 问题
2017-09-21 11:10
393 查看
问题描述:
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.
Your goal is to reach the last index in the minimum number of jumps.
示例:
For example:
Given array A =
The minimum number of jumps to reach the last index is
问题来源:Jump Game II (详细地址:https://leetcode.com/problems/jump-game-ii/description/)
思路分析:
这道题相比Jump Game 来讲,只是要求了步数最少,即到达数组末尾要求移动最少的步数,所以在这多了个步数的计算,但是应该怎么计算才合理呢?答案就是当i到达了上一步中的global的值的时候,就需要开始加一步了,也就是一步要走到global的尽头才行,所以还需要保存一个变量,用来保持步数(count)和global值的同步。
代码:
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.
Your goal is to reach the last index in the minimum number of jumps.
示例:
For example:
Given array A =
[2,3,1,1,4]
The minimum number of jumps to reach the last index is
2. (Jump
1step from index 0 to 1, then
3steps to the last index.)
问题来源:Jump Game II (详细地址:https://leetcode.com/problems/jump-game-ii/description/)
思路分析:
这道题相比Jump Game 来讲,只是要求了步数最少,即到达数组末尾要求移动最少的步数,所以在这多了个步数的计算,但是应该怎么计算才合理呢?答案就是当i到达了上一步中的global的值的时候,就需要开始加一步了,也就是一步要走到global的尽头才行,所以还需要保存一个变量,用来保持步数(count)和global值的同步。
代码:
相关文章推荐
- 《leetCode》:Jump Game II
- LeetCode - Jump Game II
- [leetcode]Jump Game II
- [LeetCode]Jump Game II(贪心&&DP!!!!!)
- Jump Game II -- LeetCode
- leetcode45 Jump Game II
- LeetCode:Jump Game II
- 【Leetcode】【python】Jump Game/Jump Game II
- [LeetCode]Jump Game II
- leetcode 45:Jump Game II
- LeetCode Jump Game II
- leetcode——Jump Game II
- Leetcode:Jump Game II
- LeetCode_Jump Game II
- LeetCode Online Judge 题目C# 练习 - Jump Game II
- leetcode笔记:Jump Game II
- 【leetcode】45. Jump Game II
- [Leetcode]Jump Game && Jump Game II
- LeetCode题目 Jump Game II
- Leetcode@Jump Game II