<html>
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.
Determine if you are able to reach the last index.
For example:
A = [2,3,1,1,4]
, return true
.
A = [3,2,1,0,4]
, return false
.
public class Solution { public boolean canJump(int[] A) { for(int i=A.length-2;i>=0;i--){ if(A[i]==0){ boolean oneStep = false; for(int j = i-1;j>=0;j--){ if(A[j]+j>i){ oneStep = true; i = j; break; } } if(!oneStep) return false; } } return true; } }
版权声明:本文为博主原创文章,未经博主同意不得转载。
举报
- 本文已收录于下面专栏:
相关文章推荐
-
LeetCode 55/45 Jump Game I/II-----Greedy**
一:Jump Game 题目: Given an array of non-negative integers, you are initially positioned at the first ...- Lu597203933
- 2015-04-10 12:30
- 820
-
LeetCode Jump Game II 前跳游戏II
Jump Game II </s- jgsj
- 2013-12-07 09:02
- 84
-
LeetCode045 Jump Game II
具体见:leetcode.com/problems/jump-game-ii Java Solution: github package leetcode; /* 大致意思是: ...- zxwtry
- 2017-04-07 21:36
- 48
-
Jump Game II -- LeetCode
原题链接:<a target="_blank" href="http://oj.leetcode.com/problems/jump-game-ii/" style="text-decoration: none; color: rgb(33,135,187); font-family: Aria- bcyy
- 2014-03-20 23:25
- 30
-
LeetCode --- 45. Jump Game II
题目链接:Jump Game II Given an array of non-negative integers, you are initially positioned at the firs...- makuiyu
- 2015-02-10 08:59
- 754
-
[LeetCode]55.Jump Game
题目 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. Determine if you are able to reach the la- SunnyYoona
- 2015-02-28 22:16
- 30
-
leetcode -- Jump Game II -- 贪心,要看
https://leetcode.com/problems/jump-game-ii/dp 会TLE思路1 会TLE參考http://chaoren.is-programmer.com/posts/4...- xyqzki
- 2015-12-22 20:23
- 267
-
[LeetCode]55.Jump Game
题目 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. Determine if you are able to reach the la- SunnyYoona
- 2015-02-28 22:16
- 16
-
Leetcode Algorithm 045. Jump Game II
Leetcode Algorithm 045. Jump Game II 给定一个非负整数的数组,数组中的元素表示从当前位置能够跳过的最长步数;从数组的第一个位置。能够经过中途的某些点跳到最后一个位置...- rinsonlo
- 2017-03-31 15:56
- 107
-
[leetcode]Jump Game
新博文地址:<a id="cb_post_title_url" style="font-size: 1.5em; line-height: 1.5em; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: #336699; text-decoration: underline;" href="http://www.cnblogs.com/huntfor/p/3898452.h- huntfor
- 2014-04-28 15:17
- 139
收藏助手
不良信息举报
0条评论