# Help me improve it , thx.

• ``````class Solution {
public:
bool canJump(int A[], int n) {
int max = A[0];
for(int i=1;i<=max && max<n-1;i++) {
if(A[i]+i > max) {
max = A[i]+i;
}
}
return max>n-2;
}
};
``````

tried my best. but i think its not good enough.

• I think your algorithm is quite neat. Can't think of a better way.
My two cents:

``````class Solution {
public:
bool canJump(int A[], int n) {
// we traverse from reverse.
int recent{n-1};
for (int i = n-2; i > -1; --i) {
if (A[i] >= recent-i) {
recent = i;
}
}
return recent == 0;
}
};
``````

• This post is deleted!

• `````` bool canJump(int A[], int n) {
int i = 0;
while(i < n){
if(i == n - 1) return true;
if(!A[i]) return false;
i  += A[i];
}
return true;
}
``````

• can this pass {2, 8, 0, 0, 0, 0}?
It think the result should be true, while your solution return false - but OJ AC pass

• Why should it be true?

• 2 jump 1 to 8, 8 jump 4 to the last index
you can run other solution to verify

• I agree what yumin829928 said.

• I thought after the first jump it will get stuck at position 2, because of 2 in 0th position.
maybe I misunderstood the question.

• This post is deleted!

• the number 2 on the first position means you can choose to jump 1 or 2 steps forward, so we can jump 1 step to "8" and then to the last index as yumin829928 mentioned. The expected result is true for this case.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.