309. Best Time to Buy and Sell Stock with Cooldown
# Medium

class Solution:
def maxProfit(self, prices: List[int]) -> int:
buy = float('-inf')
pre_buy, pre_sell, sell = 0, 0, 0
for price in prices:
pre_buy = buy
buy = max(pre_sell-price, pre_buy)
pre_sell = sell
sell = max(pre_buy+price, pre_sell)
return sell
Last updated