JAVA 7-lines Easiest DP solution, O(n), beats 89.10%


  • 0
        public int jump(int[] nums) {
            int[] dp = new int[nums.length];
            for(int i = 0, j = 1; i < nums.length && j < nums.length; ++i) {
                int end = Math.min(nums.length - 1, nums[i] + i);
                while(j <= end)
                    dp[j ++] = dp[i] + 1;
            }
            return dp[nums.length - 1];
        }
    

Log in to reply
 

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