c++ O(n) solution


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

Log in to reply
 

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