121. 买卖股票的最佳时机

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

相关文章:

  • 2022-12-23
  • 2021-09-09
  • 2021-11-02
  • 2021-08-31
  • 2021-06-09
  • 2022-01-02
  • 2022-12-23
  • 2021-11-21
猜你喜欢
  • 2021-06-21
  • 2021-12-06
  • 2021-09-26
相关资源
相似解决方案