-
-
Save parcar/964a624731d85afa2a8b9ec129e25a97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: | |
| price = [] | |
| cmax = 0 | |
| for i in prices[::-1]: | |
| cmax = i if i > cmax else cmax | |
| price.append(cmax) | |
| cmax = 0 | |
| for i in range(len(price)): | |
| profit = price.pop() - prices[i] | |
| cmax = profit if profit > cmax else cmax | |
| return cmax |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runtime: 68 ms, faster than 93.30% of Python3 online submissions for Best Time to Buy and Sell Stock.
Memory Usage: 14.7 MB, less than 5.75% of Python3 online submissions for Best Time to Buy and Sell Stock.