classSolution(object):defmaxProfit(self, prices):"""
:type prices: List[int]
:rtype: int
"""# 贪心:收集每天的正利润
result =0for i inrange(len(prices)-1):if(prices[i+1]-prices[i]>0):
result += prices[i+1]-prices[i]return result
classSolution(object):defjump(self, nums):"""
:type nums: List[int]
:rtype: int
"""
cur =0next=0
result =0iflen(nums)==1:return0for i inrange(len(nums)):next=max(next,nums[i]+i)if cur == i:
cur =next
result +=1if cur >=len(nums)-1:# 当前覆盖最远距离达到数组末尾,不用再做ans++操作,直接结束breakreturn result