A simple solution calculating remaining jumps


  • 0
    B
    def canJump(self, A):
        if len(A)==0:
            return False
        remaining=A[0]
        for i in range(1,len(A)):
            if remaining >=0:
                remaining =max(remaining,A[i-1])-1
            else:
                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.