122. 买卖股票的最佳时机 II 题目描述
class Solution:
def maxProfit(self, prices: List[int]) -> int:
if len(prices) == 0:
return 0
preP = -1
buyP = prices[0]
sumP = 0 # 总利润
for p in prices:
if preP == -1:
preP = p
else:
if p int:
if len(prices) == 0:
return 0
preP = -1
sumP = 0 # 总利润
for p in prices:
if preP != -1 :
sumP += max(0, p - preP)
preP = p
return sumP