LC045 - Jump Game II
Problem
Example
Solution
Greedy
def jump(self, nums: List[int]) -> int:
left = 0
right = 0
jumps = 0
while right < len(nums) - 1:
maxReach = 0
for i in range(left, right + 1):
maxReach = max(maxReach, i + nums[i])
# new section
left = right + 1
right = maxReach
jumps += 1
return jumpsLast updated