Time Complexity: O(n)
Space Complexity: O(1)
class Solution:
def canJump(self, nums: List[int]) -> bool:
far = 0
cur = 0
for i, num in enumerate(nums[:-1]):
if cur < i:
return False
far = max(far, i + num)
if cur == i:
cur = far
return far >= len(nums) - 1