The fastest solution in python

  • 2

    i use "begin" to record the last index which can reach the end index.
    when loop done, if begin is 0 that means we can reach the end index from the 0 index

    class Solution:
        # @param A, a list of integers
        # @return a boolean
        def canJump(self, A):
            length = len(A)
            begin = length - 1
            for i in reversed(range(length - 1)):
                if i + A[i] >= begin:
                    begin = i
            return not begin

Log in to reply

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