class Solution:
def jump(self, nums: List[int]) -> int:
cur, next = [0, 0], [1, 1]
for i in range(len(nums)):
if i > cur[1]:
cur = [next[0], next[1]]
next[0] += 1
next[1] = max(next[1], i + nums[i])
if next[1] >= len(nums)-1:
return min(len(nums)-1,next[0])
무난한 O(N) DP.. 풀기 편하긴 했다.
생각해보니 어제 문제랑 되게 비슷하네
댓글 0