Concise python O(n) solution with O(1) space


  • 0
    A
        reach = 0
        reachedEnd = False
        for i, num in enumerate(nums):
            if i < reach:
                break
            reach = max(reach, i+num)
            if reach >= len(nums)-1:
                reachedEnd = True
                break
        return reachedEnd

  • 0
    D

    if i < reach:
    break

    should be :

    if i > reach:
    break


Log in to reply
 

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