Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonGideon/662449ccbf8238c5ca43f30f1b8c48b6 to your computer and use it in GitHub Desktop.
Save JasonGideon/662449ccbf8238c5ca43f30f1b8c48b6 to your computer and use it in GitHub Desktop.
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