classSolution: defmaxProfit(self, prices) -> int: profit = 0 ifnot prices: return profit min_buyin = prices[0] max_sellout = prices[0] l = len(prices) i = 0 for buyin in prices: if i == l: return profit if min_buyin <= buyin: max_sellout = max(prices[i:]) p = max_sellout - min_buyin if p > profit: profit = p if buyin < min_buyin: min_buyin = buyin i += 1 return profit #1880 ms 14.4 MB