Python | Leetcode Python题解之第45题跳跃游戏II

题目:

Python | Leetcode Python题解之第45题跳跃游戏II_第1张图片

题解:

class Solution:
    def jump(self, nums: List[int]) -> int:
        n = len(nums)
        maxPos, end, step = 0, 0, 0
        for i in range(n - 1):
            if maxPos >= i:
                maxPos = max(maxPos, i + nums[i])
                if i == end:
                    end = maxPos
                    step += 1
        return step

你可能感兴趣的:(分享,Python,Leetcode,题解)