LeetCode.309 最佳买卖股票时机含冷冻期
buy = -prices[0]
sell = 0
stop = 0
for i in range(1, len(prices)):
buy = max(buy, sell - prices[i])
sell = max(sell, stop)
stop = buy + prices[i]
return max(sell, stop)
LeetCode.714 最佳买卖股票时机含手续费
buy = -prices[0]
sell = 0
for i in range(1, len(prices)):
buy = max(buy, sell - prices[i])
sell = max(sell, buy + prices[i] - fee)
return sell