Jump Game
public class Solution {
/**
* @param A: A list of integers
* @return: A boolean
*/
public boolean canJump(int[] A) {
int n = A.length;
boolean[] dp = new boolean[n];
dp[0] = true; //initialization
for (int i = 1; i < n; i++) {
dp[i] = false;
for (int j = 0; j < i; j++) {
if (dp[j] && A[j] >= i - j) {
dp[i] = true; //only need one j to make i become true
break;
}
}
}
return dp[n-1]; //if we can reach the last index
}
}
最后更新于
这有帮助吗?