Greedy in C++, pretty simple solution


  • 0
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
            int i=nums.size()-1,step=nums.size()-1;
            while(i>=0){
                --i;
                if(step-i<=nums[i])
                    step=i;
            }
            return step==0;
        }
    };
    

Log in to reply
 

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