본문 바로가기

0/leetcode

55. Jump Game

반응형

leetcode.com/problems/jump-game/

 

Jump Game - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        
        n = len(nums)
        i = 0
        farthest = nums[0]
        
        while i < n and i <= farthest :
            farthest = max(farthest, i+nums[i])
            i += 1
        
        return farthest >= n-1
            
반응형

'0 > leetcode' 카테고리의 다른 글

416. Partition Equal Subset Sum  (0) 2020.09.18
784. Letter Case Permutation  (0) 2020.09.10
207. Course Schedule  (0) 2020.09.08
41. First Missing Positive  (0) 2020.09.08
988. Smallest String Starting From Leaf  (0) 2020.09.08