Simple Java DP o(n) solution


  • 0
    C
    public class Solution {
        public boolean canJump(int[] nums) {
            
            int n = nums.length;
            boolean[] dp = new boolean[n];
            dp[0] = true;
            
            for(int i = 1; i < n; i++)
            {
                for(int j = i - 1; j >= 0; j--)
                {
                    if(dp[j] && (j + nums[j] >= i))
                    {
                        dp[i] = true;
                        break;
                    }
                }
            }
            
            return dp[n - 1];
            
        }
    }

Log in to reply
 

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