share my java solution


  • 0
    R
    public class Solution {
        public int jump(int[] nums) {
            int len = nums.length;
            int step = 0;
            int start = 0;
            int range = 0;
            while( range < len - 1) {
                int newRange = range;
                for(int i = start; i <= range; i++) {
                    newRange = Math.max(newRange, i + nums[i]);
                }
                step++;
                start = range + 1;
                range = newRange;
            }
            return step;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.