跳跃游戏【贪心】

Problem: 55. 跳跃游戏

文章目录

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

思路 & 解题方法

简单模拟一下就行。

复杂度

时间复杂度:

O ( n ) O(n) O(n)

空间复杂度:

O ( 1 ) O(1) O(1)

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

你可能感兴趣的:(研一开始刷LeetCode,python)