LeetCode 55. Jump Game 时间复杂度(O(n))

class Solution:
    def canJump(self, nums: [int]) -> bool:
        nums_len = len(nums)
        nums_record = [False] * nums_len
        nums_record[0] = True
        max_step = 0
        for i in range(nums_len):
            if nums_record[i] is False:
                return False
            for j in range(max_step, i + nums[i] + 1):
                if j >= nums_len - 1:
                    return True
                nums_record[j] = True
                max_step = j + 1
            if nums_record[-1] is True:
                return True
        return False

你可能感兴趣的:(leetcode,算法,职场和发展)