Beats 99.58% python submissions with 6 lines, O(n)


  • 0
    E
    def jump(self, nums):
        s,m,i,m_next=0,0,0,nums[0]
        while i<=m:
            if m>=len(nums)-1:return s
            if i+nums[i]>m_next:m_next=i+nums[i]
            if i==m:m=m_next;s+=1
            i+=1
    

Log in to reply
 

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