Python, linear time O(n), constant space O(1)


  • 0
    M

    '''

    def canJump(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        rightmost, i = 0, 0
        while i <= rightmost:
            if rightmost >= len(nums)-1:
                return True
            if i + nums[i] >rightmost:
                rightmost = i+nums[i]
            i += 1
        return False

Log in to reply
 

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