Share simple Python O(n)


  • 0
    W
    class Solution:
        # @param A, a list of integers
        # @return a boolean
        def canJump(self, A):
            m = 0
            for i in xrange(0,len(A)):
                if i<=m:
                    m = max(A[i]+i,m)
                    if m>=len(A)-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.