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 = 1for i, num in enumerate(nums):jump_max -= 1jump_max = max(jump_max, num)if jump_max == 0 and i != len(nums) - 1:return Falsereturn True