55. Jump Game
https://leetcode.com/problems/jump-game/
Input: nums = [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.Input: nums = [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.class Solution:
def canJump(self, nums: List[int]) -> bool:
nxt = 0
for cur, v in enumerate(nums):
if cur > nxt:
return False
nxt = max(nxt, cur + v)
return TrueLast updated