class Solution:
def maxProfit(self, prices: List[int]) -> int:
n = len(prices)
if n < 2:
return 0
cache1, cache2 = -prices[0], 0 # cache1: 持有, cache2: 空仓
for i in range(1, n):
old_cache1 = cache1
cache1 = max(old_cache1, cache2 - prices[i])
cache2 = max(cache2, old_cache1 + prices[i])
return cache2