python simple solution, O(N) time O(1) space, not even DP


  • 1

    At every position, I check whether I can reach this position or not, if not, then return false, otherwise update my current reach with the max of the old reach and the new reach from this position.

    class Solution(object):
        def canJump(self, nums):
            
            reach = 0
            
            for i, n in enumerate(nums):
                if reach < i:
                    return False
                reach = max(reach, i + n)
                
            return True
    

Log in to reply
 

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