Best Time to Buy and Sell Stock III LeetCode solution in Python

1
class Solution:
2
def maxProfit(self, prices: List[int]) -> int:
3
buy1, sell1, buy2, sell2 = -inf, 0, -inf, 0
4
for price in prices:
5
buy1 = max(buy1, -price)
6
sell1 = max(sell1, price + buy1)
7

8
buy2 = max(buy2, sell1 - price)
9
sell2 = max(sell2, price + buy2)
10
return sell2

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0