从前往后遍历class Solution: def maxProfit(self, prices: List[int]) - int: if (len(prices)1): return 0 max_profit 0 min_price float(inf) for i in range(len(prices)): if prices[i] min_price: min_price prices[i] if max_profit (prices[i]-min_price): max_profit prices[i]-min_price return max_profit