max_profit.py 285 B

1234567891011121314
  1. from typing import List
  2. import heapq
  3. def maxProfit(prices: List[int]) -> int:
  4. inf = int(1e9)
  5. min_price = inf
  6. max_profit = 0
  7. for price in prices:
  8. max_profit = max(price - min_price, max_profit)
  9. min_price = min(price, min_price)
  10. return max_profit