public class Solution {
/**
* @param A: A list of integers
* @return: The boolean answer
*/
public boolean canJump(int[] A) {
// 2015-05-15
if (A == null || A.length == 0) {
return false;
}
int n = A.length;
boolean[] can = new boolean[n];
can[0] = true;
for (int i = 1; i < n; i++) {
can[i] = false;
for (int j = 0; j < i; j++) {
if (can[j] == true && j + A[j] >= i) {
can[i] = true;
break;
}
}
}
return can[n - 1];
}
}
public class Solution {
/**
* @param A: A list of integers
* @return: The boolean answer
*/
public boolean canJump(int[] A) {
// wirte your code here
if (A == null || A.length == 0) {
return false;
}
// 默认初始化为false
boolean[] can = new boolean[A.length];
can[0] = true;
for (int i = 0; i < A.length; i++) {
if (!can[i]) {
continue;
}
for (int j = i + 1; j <= i + A[i]; j++) {
if (j < A.length)
can[j] = true;
}
}
return can[A.length - 1];
}
}
[LintCode]Jump Gamepublic class Solution { /** * @param A: A list of integers * @return: The boolean answer */ public boolean canJump(int[] A) { // 2015-05-15