5-line Python solution

  • 4
    def canJump(self, nums):
        max_reach, n = 0, len(nums)
        for i, x in enumerate(nums):
            if max_reach < i: return False
            if max_reach >= n - 1: return True
            max_reach = max(max_reach, i + x)

Log in to reply

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