题目链接
https://leetcode.cn/problems/jump-game-ii/description/
文章来源地址https://www.toymoban.com/news/detail-708284.html
代码
class Solution:
def jump(self, nums: List[int]) -> int:
if len(nums) == 1:
return 0
curdis = 0
nextdis = 0
step = 0
for i in range(len(nums)):
nextdis = max(nums[i] + i, nextdis)
if i == curdis:
step += 1
curdis = nextdis
if nextdis >= len(nums) - 1:
break
return step
文章来源:https://www.toymoban.com/news/detail-708284.html
到了这里,关于LeetCode(力扣)45. 跳跃游戏 IIPython的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!