C++ Solved with DP


  • 0
    M
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
            vector<int> maxJump(nums.size(),0);
            maxJump[0] = nums[0];
            for(int i = 1; i < nums.size(); i++) {
                if(maxJump[i-1] < i) return false;
                maxJump[i] = max(maxJump[i-1],nums[i]+i);
            }
            return true;
        }
    };
    

Log in to reply
 

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