JAVA short solution


  • 0
    W
    public class Solution {
        public int jump(int[] nums) {
            int count = 0;
            int max = 0;
            for (int i = 0, newMax = 0; i <= newMax && i < nums.length - 1; i++){
                newMax = Math.max(newMax, nums[i] + i);
                if (i == max){
                    count++;
                    max = newMax;
                }
            }
            return max >= nums.length - 1 ? count : -1;
        }
    }

Log in to reply
 

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