class Solution:
def maxProfit(self, prices: List[int]) -> int:
if len(prices) < 2:
return 0
buys = [float('-inf')] * len(prices)
sells = [0] * len(prices)
buys[0] = -prices[0]
for i in range(1, len(prices)):
buys[i] = max(buys[i-1], sells[i-1] - prices[i])
sells[i] = max(sells[i-1], buys[i-1] + prices[i])
return sells[-1]