45. Jump Game II - pangeneral/leetcode-notebook GitHub Wiki

We use far to record current furthest place we can reach. Traverse the array to update far, each time current place reach the furthest place the step plus one. Keep traversing until far reach the last place of array.

    public int jump(int[] nums) {
        int far = 0, result = 0, i = 0;
        while( i < nums.length && far < nums.length - 1 ) {
            int max = 0;
            while( i <= far ) {
                max = Math.max(max, nums[i] + i);
                i++;
            }
            far = max;
            result++;
        }
        return result;
    }