class Solution { public: int jump(vector<int>& nums) { int n=nums.size(); int cr=0, cmx=0, j=0; for(int i=0;i<n-1;i++) { if(i+nums[i]>cmx) cmx=i+nums[i]; if(i==cr) { j++; cr=cmx; } } return j; } };
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