[Leetcode] 55. Jump Game

천호영·2023년 10월 26일
0

LeetCodeTop100

목록 보기
4/17

문제

https://leetcode.com/problems/jump-game/description/?envType=study-plan-v2&envId=top-100-liked

풀이

최대 도달 가능한 인덱스의 위치를 계속해서 갱신시켜 나가서 정답을 찾았습니다.

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        max_index = 0
        for i, num in enumerate(nums):
            if i <= max_index:
                max_index = max(max_index, i+num)

        return max_index >= len(nums)-1 # 마지막 인덱스보다 크거나 같으면 도달 가능
profile
성장!

0개의 댓글