class Solution:
def maxProfit(self, prices: List[int]) -> int:
i=0;
j=1;
money=0;
while j<len(prices):
t=prices[j]-prices[i];
if t>0:
money = money + t;
i=i+1;
j=i+1;
else:
if (prices[j]-prices[i])<=0:
i=i+1;
j=i+1;
return money;
这是自己写的笨办法。。。
class Solution(object):
def maxProfit(self, prices):
return sum(max(prices[i + 1] - prices[i], 0) for i in range(len(prices) - 1))
再看大佬的= =,有毒,一行结束,智商碾压。