Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class Solution:
def maxProfit(self, prices: List[int]) -> int:
buy1,buy2 = -sys.maxsize,-sys.maxsize
profit1,profit2 = 0,0
for price in prices:
buy1 = max(buy1, -price)
profit1 = max(profit1, buy1 + price)
buy2 = max(buy2, profit1 - price)
profit2 = max(profit2, buy2 + price)
return profit2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.