Easy python O(N)


  • 0
    S

    Beats 81.08%

        def canJump(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            n = len(nums)
            h = []
            for i in range(n):
                h.append(i+nums[i])
            i = 0
            r = nums[0]
            while r < n:
                m = max(h[i:r+1])
                if m > r:
                    i = r+1
                    r = m
                else:
                    break
            if r >= 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.