Easy Python Solution - Linear


  • 0
    M
    class Solution(object):
        def canJump(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            
            if nums==None or nums==[] or nums[0]==0 and len(nums)>1:
                return False
                
            far=nums[0]
            
            for i in range(len(nums)):
                if far>=len(nums)-1:
                    return True
                if i<=far:
                    far=max(far,i+min(nums[i],len(nums)))
    
            
            return False
    

    For simplicity, some overlapping cases are not removed.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.