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

 时间复杂度(O(n)),思想:动态规划

class Solution:
    def canJump(self, nums: [int]) -> bool:
        nums_len = len(nums)
        if nums[0] == 0 and nums_len > 1: return False
        path_status = [False] * nums_len
        path_status[0] = True
        path_index = 0
        path_count = 1
        for index, num in enumerate(nums):
            while path_index <= index + num:
                if path_index <= index: path_index = path_index + 1
                if path_index >= nums_len: break
                path_status[path_index] = True
                path_index += 1
                path_count += 1
        return path_count == nums_len

 

你可能感兴趣的:(LeetCode)