C++ straight forward solution


  • 0
    S
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
            int s=nums.size();
            vector<bool> dp(s);
            dp[s-1]=true;
            int mark=s-1;
            for(int i=s-2;i>=0;i--) {
                if(nums[i]+i>=mark) {
                    dp[i]=true;
                    mark=i;
                }
                /*
                for(int j=nums[i];j>=0;j--) {
                    if(i+j<s&&dp[i+j]==true) {
                        dp[i]=true;
                        break;
                    }
                }
                */
            }
            return dp[0];
        }
    };
    

Log in to reply
 

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