AlgoMaster Logo

Jump Game II

nums=[2, 3, 1, 1, 4]
1public int jump(int[] nums) {
2    int jumps = 0;
3    int currEnd = 0;
4    int farthest = 0;
5
6    for (int i = 0; i < nums.length - 1; i++) {
7        farthest = Math.max(farthest, i + nums[i]);
8
9        if (i == currEnd) {
10            jumps++;
11            currEnd = farthest;
12        }
13    }
14
15    return jumps;
16}
0 / 12
0213213144