标签:style blog class code c java
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) { if(A.length==0) return true; Boolean[] bol = new Boolean[A.length]; Arrays.fill(bol, false); bol[0]=true; for(int i=1;i<A.length;i++){ for(int j=0;j<i;j++){ if(bol[j]&&(A[j]+j)>=i){ bol[i]=true; break; } } } return bol[A.length-1]; } }
【LeetCode】Jump Game,布布扣,bubuko.com
标签:style blog class code c java
原文地址:http://www.cnblogs.com/yixianyixian/p/3732168.html