121. 买卖股票的最佳时机

题目python

python

class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """
        if len(prices) < 2: return 0 profit = 0 mininum = prices[0] for i in prices: mininum = min(i,mininum) profit = max(i-mininum,profit) return profit

思路:spa

同时保留最小值和最大差值code

相关文章
相关标签/搜索