Best Time to Buy and Sell Stock III LeetCode solution in Python
1class Solution:2def maxProfit(self, prices: List[int]) -> int:3buy1, sell1, buy2, sell2 = -inf, 0, -inf, 04for price in prices:5buy1 = max(buy1, -price)6sell1 = max(sell1, price + buy1)78buy2 = max(buy2, sell1 - price)9sell2 = max(sell2, price + buy2)10return sell2