Short approach faster than O(n) C++


#1

int Solution::canJump(vector &A) {
int n=A.size();
if(n<=1)
return 1;
int m=0;
for(int i=0;i<n;i++)
{
if(i>m)
return 0;
else
{
if(i==n-1)
return 1;
m=max(m,i+A[i]);
if(m==n-1)
return 1;
}
}
return 0;
}