Clear greedy Solution for c++


  • 5
    L
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
           if(nums.size() <= 1)return true;
           int step = nums[0];
           for(int i = 1; i < nums.size() - 1 && step != 0; i++){
               step--;
               step = max(step,nums[i]);//keep the step or change to the biggest step we can go now
           }
           return step != 0;
        }
    };

Log in to reply
 

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