CODE 88: Jump Game II
来源:互联网 发布:天猫美工工资一般多少 编辑:程序博客网 时间:2024/05/29 11:29
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.)
public int jump(int[] A) {// Start typing your Java solution below// DO NOT write main() functionif (null == A || A.length <= 1)return 0;int maxIndex = 0;int i = 0;int length = A.length;int step = 0;while (i < length && i <= maxIndex) {int tmpMaxIndex = maxIndex;while (i <= tmpMaxIndex) {if (i + A[i] > maxIndex)maxIndex = i + A[i];++i;}++step;if (maxIndex >= length - 1)return step;}return -1;}
- CODE 88: Jump Game II
- 88:Jump Game II
- Leet Code—Jump Game II
- Jump Game &Jump Game II
- Jump Game/Jump Game II
- CODE 78: Jump Game
- [leet code] Jump Game
- 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
- 卸载Ubuntu之后系统启动项留下了一个neogrub,如何删除
- android 用pull解析xml的错误~!!
- OCP-1Z0-051-V9.02-174题
- 怎么卸载安装在Ubuntu下的gcc?
- UVa 465 Overflow (比较大小难道不应该用double吗)
- CODE 88: Jump Game II
- 感谢LP
- 如何避免JDBC内存溢出问题
- autohotkey +vba 利用文本文件传递数据(2)-中断与延时
- struts2
- Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name
- UVa 748 / POJ 1001 Exponentiation (浮点高精度求幂&正则表达式的应用)
- 马尔可夫随机场(Markov Random Field)
- Socket