먼저 최대거리로 포인터를 옮기고 진행이 불가능하면 하나씩 뒤로 무르는 backtracking 이 떠올랐다. 하지만 visit 을 체크하는 과정에서 비효율적이라는 생각이 들어 기각했다.
class Solution:
def canJump(self, nums: list[int]) -> bool:
pointer = 0
reach = nums[pointer]
if reach + 1 >= len(nums):
return True
while pointer < reach:
pointer += 1
reach = max(reach, pointer + nums[pointer])
if reach + 1 >= len(nums):
return True
return False