------
## 最终结论
```python
def maxProfit(prices):
    if not prices:
        return 0
    
    # Initialize the variables for two transactions
    first_buy, first_sell = float('-inf'), 0
    second_buy, second_sell = float('-inf'), 0
    
    for price in prices:
        # For the first transaction
        first_buy = max(first_buy, -price)
        first_sell = max(first_sell, first_buy + price)

        # For the second transaction
        second_buy = max(second_buy, first_sell - price)
        second_sell = max(second_sell, second_buy + price)
    
    return second_sell
```