Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Given an array of non-negative integers nums, you are initially positioned at the first index of the array.
- Each element in the array represents your maximum jump length at that position.
- Your goal is to reach the last index in the minimum number of jumps.
- You can assume that you can always reach the last index.
- '''
- class Solution:
- def jump(self, nums: List[int]) -> int:
- l,r=0,0
- count,n,window=0,len(nums),0
- while r<n-1:
- count+=1
- for x in range(l,r+1):
- window=max(window,nums[x]+x)
- l=r+1
- r=window
- return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement