我真的是超开心了,又做对了!!!!!!而且没走啥弯路!!!!!!!
class Solution(object): def jump(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)<2: return 0 pact=0 i=0 while i<len(nums): if nums[i]>=len(nums)-i-1: pact+=1 return pact else: pact+=1 m=0 k=[0] for j in range(i,i+nums[i]+1): if nums[j]>=len(nums)-j-1: pact+=1 return pact else: if j+nums[j]>m: m=j+nums[j] k[0]=j i=k[0]
执行用时 :88 ms, 在所有 python 提交中击败了90.09%的用户
内存消耗 :13.3 MB, 在所有 python 提交中击败了32.95%的用户
执行用时为 68 ms 的范例 class Solution(object): def jump(self, nums): """ :type nums: List[int] :rtype: int """ cur = pre = step = 0 for i in range(len(nums)-1): cur = max(cur,nums[i]+i) if i == pre: step += 1 pre = cur return step
——2019.10.14
原文地址:https://www.cnblogs.com/taoyuxin/p/11671059.html
时间: 2024-10-08 19:07:45