classSolution: defmaxProfit(self, prices: List[int]) -> int: n = len(prices) if n == 0: return0 dp = [0] * n minn = prices[0] for i inrange(1, n): dp[i] = max(dp[i-1], prices[i]-minn) minn = min(minn, prices[i]) maxx, maxp, res = prices[-1], 0, max(dp) for i inrange(n-2, 0, -1): maxp = max(maxp, maxx-prices[i]) maxx = max(maxx, prices[i]) res = max(res, dp[i-1]+maxp) return res