```
class Solution {
public:
bool canJump(vector<int>& nums) {
int pos = 0;
int limit = nums[0];
int n = nums.size();
while(pos<limit && pos<n)
{
pos++;
if(pos<n && pos+nums[pos]>limit)
limit = pos+nums[pos];
}
return (pos>=n-1);
}
};
```