Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def maxProfit(self, prices: List[int]) -> int:
- min_price_so_far = float("inf")
- max_profit = 0
- for i in range(len(prices)):
- max_profit_so_far = prices[i] - min_price_so_far
- max_profit = max(max_profit, max_profit_so_far)
- min_price_so_far = min(prices[i], min_price_so_far)
- return max_profit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement