puzzles/maximum-profit/maximum_profit.py

11 lines
228 B
Python
Raw Normal View History

2024-04-02 21:01:09 +00:00
prices = [7, 1, 5, 3, 6, 4]
buy_price = prices[0]
max_profit = max(0, prices[1] - buy_price)
for price in prices:
max_profit = max(0, max_profit, price - buy_price)
buy_price = min(buy_price, price)
print(max_profit)