首页 > 代码库 > [LeetCode]45 Jump Game II
[LeetCode]45 Jump Game II
https://oj.leetcode.com/problems/jump-game-ii/
http://blog.csdn.net/linhuanmars/article/details/21356187
public class Solution { public int jump(int[] A) { // [2, 3, 1, 1, 4] // [2, 1, 2, 1, 0] if (A == null || A.length <= 1) return 0; int len = A.length; int start = 0; int end = 0; int jump = 0; while (end < len) { int maxCanGo = 0; jump ++; for (int i = start ; i <= end ; i ++) { int curValue = A[i] + i; if (curValue >= len - 1) { // Reached return jump; } if (curValue > maxCanGo) { maxCanGo = curValue; } } if (maxCanGo <= end) { // Can not go further return -1; } start = end + 1; end = maxCanGo; } return jump; } }
[LeetCode]45 Jump Game II
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。