A simple solution calculating remaining jumps

  • 0
    def canJump(self, A):
        if len(A)==0:
            return False
        for i in range(1,len(A)):
            if remaining >=0:
                remaining =max(remaining,A[i-1])-1
                remaining =-1
        return remaining >=0

    it calculates the remaining jumps one has when he arrives at A[i]. And apparently this value has to be >=0 for A[i] to be reachable

Log in to reply

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