puzzles/maximum-profit/maximum_profit.py
Zoé Cassiopée Gauthier 7e4f02547b Initial commit
2024-04-02 17:01:09 -04:00

11 lines
228 B
Python

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)