classSolution:defjump(self, nums: List[int])->int:iflen(nums)==1:return0
cur_distance =0# 当前覆盖最远距离下标
ans =0# 记录走的最大步数
next_distance =0# 下一步覆盖最远距离下标# 需要计算最小跳跃次数。贪心的话,依然是每次选最大的。for i inrange(len(nums)):
next_distance =max(i+nums[i], next_distance)if i == cur_distance:
ans +=1
cur_distance = next_distance
if next_distance >=len(nums)-1:return ans