classSolution:defmaxProfit(self,prices: List[int]) ->int:iflen(prices)<2:return0 buys = [float('-inf')] *len(prices) sells = [0] *len(prices)for i inrange(len(prices)): buys[i]=max(buys[i-1] if i >0else-prices[i], (sells[i-2] if i >1else0) - prices[i]) sells[i]=max(sells[i-1] if i >0else0, (buys[i-1] + prices[i] if i >0else0))return sells[-1]