a simple O(n) python solution

  • 0
    class Solution(object):
        def canJump(self, nums):
            :type nums: List[int]
            :rtype: bool
            n,next_max = len(nums),0
            for x in range(n):
                if x > next_max:return False
                next_max = max(next_max,nums[x]+x)
            if next_max>=n-1:return True
            return False

Log in to reply

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