Python O(n) - from the end, when found a zero, it tries to jump it


  • 0
    A

    """

    def canJump(self, nums):
        
        r = len(nums) - 2
        while r >= 0:
            l = r
            while nums[l] <= r-l:
                l -= 1
                if l < 0:
                    return False
            r = l
            while r >= 0 and nums[r]:
                r -= 1
        return True
    

    """


Log in to reply
 

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