class Solution {
public:
bool canJump(vector<int>& nums) {
int n=nums.size();
int mxReach=0;
for(int i=0;i<n;i++)
{
if(i>mxReach) return false;
mxReach=max(mxReach, i+nums[i]);
}
return true;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter