LeetCode45. 跳跃游戏 II
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/jump-game-ii/description/
代码
class Solution:def jump(self, nums: List[int]) -> int:if len(nums) == 1:return 0curdis = 0nextdis = 0step = 0for i in range(len(nums)):nextdis = max(nums[i] + i, nextdis)if i == curdis:step += 1curdis = nextdisif nextdis >= len(nums) - 1:breakreturn step