Участник:Alexryabov/Taskjumpgameii

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

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

class Solution(object):
    def jump(self, nums):
 
        total_length = len(nums) - 1
 
        steps = 0
        right = 0
        far = 0
 
        for i in range(0, total_length):
            far = max(far, i + nums[i])
 
            if far >= total_length: return steps + 1
 
            if i == right: 
                steps += 1
                right = far
 
        return 0