1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ maxprofit = 0 tempmin = float('inf') for i in range(len(prices)): if tempmin > prices[i]: tempmin = prices[i] else: maxprofit = max(maxprofit, prices[i]-tempmin) return maxprofit