16ms c++ easy understand


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

Log in to reply
 

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