Jump Game II(另类BFS)
来源:互联网 发布:ec6108v9不能安装软件 编辑:程序博客网 时间:2024/06/07 16:27
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.)
Note:
You can assume that you can always reach the last index.
class Solution {public: int jump(vector<int>& nums) { int l=0,r=0; int maxr=-1; int ans=0; int n=nums.size(); while(1) { if(r>=n-1) return ans; for(int i=l;i<=r;i++) { maxr=max(maxr,nums[i]+i); } l=r+1; r=maxr; ans++; } }};
阅读全文
0 0
- Jump Game II(另类BFS)
- Jump Game II一道优化bfs题
- Jump Game &Jump Game II
- Jump Game/Jump Game II
- LeetCode: Jump Game II
- LeetCode Jump Game II
- LeetCode: Jump Game II
- [Leetcode] Jump Game II
- [LeetCode] Jump Game II
- [Leetcode] Jump Game ii
- leetcode Jump Game II
- Jump Game II
- Jump Game II
- Jump Game II
- leetcode Jump Game II
- [LeetCode]Jump Game II
- Jump Game II
- Jump Game II
- 进程间通信——消息队列
- LinuxStudyNote(34)-Linux常用命令(9)shutdown关机重启命令
- ArcGis 地理数据库的容灾备份
- tmux
- HDOJ3_A+B for Input-Output Practice
- Jump Game II(另类BFS)
- 电信采集系统项目
- Java中基本数据类型的范围
- 【广告算法工程师入门 11】机制设计-拍卖理论基础
- SQL SERVER 存储过程中SELECT 返回值如何赋值给变量
- 374. Guess Number Higher or Lower
- Qt 屏蔽系统按键、任务管理器、任务栏、鼠标,修改注册表
- 垃圾收集与分配策略——(二)垃圾收集算法
- JavaScript 实现百度换肤