For i < n − 1: farthest = max(farthest, i + nums[i]); if i == end, jumps++ and end = farthest.
Approach 1
class Solution {
public int jump(int[] nums) {
int jumps = 0, end = 0, farthest = 0;
for (int i = 0; i < nums.length - 1; i++) {
farthest = Math.max(farthest, i + nums[i]);
if (i == end) { jumps++; end = farthest; }
}
return jumps;
}
}