try every reachable index.
bool canJump(int A[], int n) {
int start = 0, end = 0;
while (start <= end && end < n-1)
{
end = max(end, start + A[start]);
start++;
}
return end >= (n-1);
}
No comments:
Post a Comment