Simple O(n) python solution
920ms, faster than 96.58%\n\nclass Solution:\n    def maxProfit(self, prices: List[int]) -> int:\n        max_profit = 0\n        best_price_to_buy = prices[0]\
920ms, faster than 96.58%\n```\nclass Solution:\n    def maxProfit(self, prices: List[int]) -> int:\n        max_profit = 0\n        best_price_to_buy = prices[0]\n        for price in prices:\n            if price < best_price_to_buy:\n                best_price_to_buy = price\n            elif price > best_price_to_buy:\n                profit = price - best_price_to_buy\n                if profit > max_profit:\n                    max_profit = profit\n        return max_profit\n```
['Python', 'Python3']