Python 4 liner, beats 96% other solutions.

  • 3

    This question appeared to be a bit confusing to me at first... Then I realised it should be
    a easy question... lol


    class Solution(object):
        def canJump(self, nums):
            reach = 0
            for i in xrange(len(nums)):
                if reach >= i and i+nums[i] > reach: reach = i+nums[i]            
            return reach >= len(nums)-1


    reach is the farthest position to which nums[i] can jump.

Log in to reply

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