6 lines clean DP solution in Python


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

Log in to reply
 

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