Участник:Alexander Denisenko/jump game ii

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/jump-game-ii/

class Solution:
    def jump(self, nums):
        if len(nums) == 1:
            return 0
 
        n = len(nums)
        jump_length = nums[0]
        reach = nums[0]
        count = 1
 
        for i in range(n - 1):
            curr = nums[i]
            reach = max(reach, curr + i)
 
            if jump_length == 0:
                count += 1
                jump_length = reach - i
 
            jump_length -= 1
 
        return count