Best Time to Buy and Sell Stock LeetCode solution in Python
1# Runtime: 2509 ms (Top 5.01%) | Memory: 25 MB (Top 86.17%)234class Solution:5def maxProfit(self, prices):6left = 0 # Buy7right = 1 # Sell8max_profit = 09while right < len(prices):10currentProfit = prices[right] - prices[left] # our current Profit11if prices[left] < prices[right]:12max_profit = max(currentProfit, max_profit)13else:14left = right15right += 116return max_profit