45. Jump Game II

Question

CleanShot 2024-11-09 at 15.16.23.png

Code

class Solution(object):
    def jump(self, nums):
        res = 0

        l = r = 0

        while r < len(nums) - 1:
            farthest = 0

            for i in range(l, r + 1):
                farthest = max(farthest, nums[i] + i)

            l = r + 1
            r = farthest
            res += 1

        return res