Fastest Python O(n) constant space solution - 6 lines

  • 0

    Checking the range of the current element, decreasing by 1 and comparing to the next element. Currently the fastest Python solution.

    class Solution:
        def canJump(self, nums):
            :type nums: List[int]
            :rtype: bool
            cur_range = nums[0]
            for i in range(0, len(nums)-1):
                cur_range = max(cur_range - 1, nums[i])
                if cur_range == 0:
                    return False
            return True

  • 0

    Currently the fastest Python solution.

    What is/was the time?

  • 0

    The time was 68ms. But it seems that the time is non-deterministic, as I've just run it again and got
    72ms, and then again and it was 82ms.

Log in to reply

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