45. Jump Game
class Solution:
def jump(self, nums: List[int]) -> int:
minimums = {}
# collect the list of jumps required from each item in list
jumpsStore = [0]*len(nums)
# until I reach the end of the array (guaranteed to reach)
for i in range(len(nums)-2, -1, -1):
if nums[i] == 0:
jumpsStore[i] = float('inf')
continue
jumpZone = 0
jump_capacity = nums[i]
if (i + jump_capacity) < len(nums):
jumpZone = nums[i]
else:
jumpZone = len(nums)-1
jumpsStore[i] = 1 + (min(jumpsStore[i+1: i+(jumpZone)+1 ]))
return jumpsStore[0]
Last update :
6 décembre 2023
Created : 6 décembre 2023
Created : 6 décembre 2023