Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active February 26, 2020 16:43
Show Gist options
  • Save deque-blog/2776a197f4deec07f32a218cf818af43 to your computer and use it in GitHub Desktop.
Save deque-blog/2776a197f4deec07f32a218cf818af43 to your computer and use it in GitHub Desktop.
def maxProfit(prices: List[int]) -> int:
max_profit = 0
buy_time = 0
for sell_time in range(1, len(prices)):
if prices[sell_time] < prices[buy_time]:
buy_time = sell_time
else:
max_profit = max(max_profit, prices[sell_time] - prices[buy_time])
return max_profit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment