Jump Game II (最小步数到达终点,贪心) 【leetcode】
来源:互联网 发布:matlab教程矩阵 编辑:程序博客网 时间:2024/06/07 07:19
题目:
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 1
step from index 0 to 1, then 3
steps to the last index.)
这题就是已知能到达终点,问最小的步数。
依旧贪心去推,贪心的规则就是在能够到达的范围之内,选择一个能够到达最远距离的点,更新步数,和更新最远到达的范围。
class Solution {public: int jump(int A[], int n) { int maxx=0,temp=0,num=0; for(int i=0;i<n;) { if(temp>=n-1)break; while(i<=temp) { maxx=max(maxx,i+A[i]); ++i; } num++; temp=maxx; } return num; }};
- Jump Game II (最小步数到达终点,贪心) 【leetcode】
- Jump Game II 最小到达终点的步数
- Jump Game II 到达终点的最小步数 模拟
- Jump Game (能否到达终点,贪心) 【leetcode】
- [LeetCode]Jump Game II (贪心,维护当前最远能到达的位置和所需最少步数)
- Jump Game II 跳跃游戏(求跳到最后一个的最小步数) @LeetCode
- Leetcode 贪心 Jump Game II
- [leetcode][贪心] Jump Game II
- LeetCode Jump Game II(贪心)
- [LeetCode]Jump Game II(贪心&&DP!!!!!)
- leetCode #45 Jump Game II 贪心
- leetcode -- Jump Game II -- 贪心,要看
- Jump Game II leetcode 45 贪心
- LeetCode 45. Jump Game II|贪心算法
- [LeetCode]45. Jump Game II &&贪心算法
- 贪心 Jump Game II
- Leetcode 贪心 Jump Game
- [leetcode][贪心] Jump Game
- poj 1836 Alignment
- URAL 1736 Chinese Hockey(网络最大流)
- JAVA自己实现的文件压缩解压
- 最新3D思维导图软件imindmap6破解版/中文汉化版免费下载~乐趣尽在其中
- java集合类
- Jump Game II (最小步数到达终点,贪心) 【leetcode】
- HDU 4721 Food and Productivity (二分+树状数组)
- ultraedit
- Ural 1732. Ministry of Truth 多串匹配KMP
- URAL 1741 Communication Fiend
- 比较两个文件相同的地方
- POJ 2479 Maximum sum(DP)
- 调用栈
- C语言运算符优先级 详细列表