You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param {number[]} nums * @return {number} *//*every time i move forward to next index, which mean + 1i will touch each single index, as long as we reach the currentJumpEnd, that means we should ready for next jumpTime complexityL O(n) because there are NN elements in the array and we visit each element in the array only once.Space Complexity: O(1)because we don't use any additional data structures.*/varjump=function(nums){letfarthest=0,curJumpEnd=0,jump=0;for(leti=0;i<nums.length-1;i++){farthest=Math.max(farthest,nums[i]+i);if(i===curJumpEnd){jump++;curJumpEnd=farthest;}}returnjump;};