Problem: 55. 跳跃游戏
简单模拟一下就行。
时间复杂度:
O ( n ) O(n) O(n)
空间复杂度:
O ( 1 ) O(1) O(1)
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