Created
June 28, 2019 23:37
-
-
Save JasonGideon/662449ccbf8238c5ca43f30f1b8c48b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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