class Solution: def maxProfit(self, prices: List[int]) -> int: max_profit = 0 buy_index = 0 if len(prices) == 1: return 0 for i, cur_price in enumerate(prices): profit = cur_price - prices[buy_index] if profit > max_profit: max_profit = profit elif cur_price < prices[buy_index]: buy_index = i return max_profit