10 lines BFS time (n) space O(1)


  • 0
    H
    public int jump(int[] nums) {
        if(nums == null || nums.length <= 1) return 0;
        int jump = 1, len = nums.length, max = nums[0], count = 1;
        while(max<len - 1){
            count++;
            int prevmax = max;
            for(; jump <= prevmax; jump++){
                max = Math.max(max, jump+nums[jump]);
            }
        }
        return count;
    }

Log in to reply
 

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