Problem: 55. 跳跃游戏


文章目录

  • 思路 & 解题方法
  • 复杂度
  • Code


思路 & 解题方法

简单模拟一下就行。

复杂度

时间复杂度:

跳跃游戏【贪心】_空间复杂度

空间复杂度:

跳跃游戏【贪心】_空间复杂度_02

Code

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        jump_max = 1

        for i, num in enumerate(nums):
            jump_max -= 1
            jump_max = max(jump_max, num)
            if jump_max == 0 and i != len(nums) - 1:
                return False
        return True