python45. 跳跃游戏 II
作者:互联网
class Solution:
def jump(self, nums: List[int]) -> int:
# 能跳到的最远距离
max_jump=0
# 记录跳跃次数
step=0
# 记录每一步跳跃可以到的区间的最后一个元素,用于记录何时step+=1
end=0
for i in range(len(nums)-1):
max_jump=max(max_jump,nums[i]+i)
if end==i:
step+=1
end=max_jump
return step
解释转自leecode
作者:wu_yan_zu
链接:https://leetcode-cn.com/problems/jump-game-ii/solution/tan-xin-suan-fa-zhu-xing-jie-shi-python3-by-zhu_sh/
来源:力扣(LeetCode)
标签:jump,end,python45,max,nums,II,step,跳跃 来源: https://blog.csdn.net/qq_44243729/article/details/122619767