Skip to content

Instantly share code, notes, and snippets.

@parcar
Created August 22, 2019 15:47
Show Gist options
  • Select an option

  • Save parcar/964a624731d85afa2a8b9ec129e25a97 to your computer and use it in GitHub Desktop.

Select an option

Save parcar/964a624731d85afa2a8b9ec129e25a97 to your computer and use it in GitHub Desktop.
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
@parcar
Copy link
Author

parcar commented Aug 22, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment