Another sexy O(n) approach


#1

int Solution::canJump(vector &A) {
int b1;
int n=A.size()-1;
if(n+1==1)
return 1;
int pos=n-1;
while(pos>=0)
{
if(pos==0 && A[pos]>=(n-pos)){
b1=1;

   }
   else if(pos==0 && A[pos]<(n-pos))
   {
      
      b1=0;
    
   }
   if(A[pos]>=(n-pos))
   {
       n=pos;
       pos--;
   }
   else 
   {
       pos--;
   }

}
return b1;

}