LeetCode(力扣)55. 跳跃游戏Python

LeetCode20. 有效的括号

    • 题目链接
    • 代码

题目链接

https://leetcode.cn/problems/jump-game/
LeetCode(力扣)55. 跳跃游戏Python_第1张图片

代码

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

你可能感兴趣的:(leetcode,游戏,python)