Single loop python solution


  • 1
    Z
    class Solution(object):
        def jump(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            length = len(nums)
            index = 0
            longest = 0
            steps = 0
            max = 0
      
            while index < length:
           
               long = index + nums[index]  
               if index <= longest:
                   if long > max:
                        max = long
                   if index == longest:
                       if longest >= length -1 :
                           return steps
                       longest = max
                       steps += 1 
     
               index += 1
                        
            return steps         
    

Log in to reply
 

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