Simple Python solution - O(n-1) 55ms


  • 2
    G
    class Solution:
        # @param {integer[]} nums
        # @return {boolean}
        def canJump(self, nums):
            stepsLeft = nums[0]
    
            if not stepsLeft and len(nums) > 1:
                return False
    
            for num in nums[1:-1]:
                stepsLeft = max(stepsLeft - 1, num)
                if not stepsLeft:
                    return False
    
            return True

Log in to reply
 

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