题目标题

(Leetcode)买卖股票的最佳时机

参考解析
  1. class Solution:
  2. def maxProfit(self, prices: List[int]) -> int:
  3. inf = int(1e9)
  4. minprice = inf
  5. maxprofit = 0
  6. for price in prices:
  7. maxprofit = max(price - minprice, maxprofit)
  8. minprice = min(price, minprice)
  9. return maxprofit