相对于后面的几个来说非常简单,一个for就搞定了
class Solution:
def maxProfit(self, prices: List[int]) -> int:
l=len(prices)
diff,lirun=0,0
for i in range(1,l):
diff=prices[i]-prices[i-1]
if diff>=0:
lirun=lirun+diff
return lirun