sell_stock.py
python_old/sell_stock.py
def maxProfit(prices: list[int]) -> int:
min_price = float('inf')
max_profit = 0
for i, price in enumerate(prices):
if price < min_price:
min_price = price
print(f"Day {i}: New minimum price found: {min_price}")
else:
profit = price - min_price
print(f"Day {i}: Selling at {price} with min price {min_price} → profit = {profit}")
if profit > max_profit:
max_profit = profit
print(f"Day {i}: New max profit updated to: {max_profit}")
print(f"Final maximum profit: {max_profit}")
return max_profit
if __name__ == "__main__":
print(maxProfit([8,2,1,5,9,3,6,4,7]))
Artículos relacionados
01_classical_caesar_cipher.py
01_classical_caesar_cipher.py — python source code from the python old learning materials (python_old/Cryptography/01_classical_caesar_cipher.py).
Leer artículo →02_classical_monoalphabetic.py
02_classical_monoalphabetic.py — python source code from the python old learning materials (python_old/Cryptography/02_classical_monoalphabetic.py).
Leer artículo →03_classical_rail_fence.py
03_classical_rail_fence.py — python source code from the python old learning materials (python_old/Cryptography/03_classical_rail_fence.py).
Leer artículo →04_frequency_analysis.py
04_frequency_analysis.py — python source code from the python old learning materials (python_old/Cryptography/04_frequency_analysis.py).
Leer artículo →05_cryptographic_hashing.py
05_cryptographic_hashing.py — python source code from the python old learning materials (python_old/Cryptography/05_cryptographic_hashing.py).
Leer artículo →06_password_hashing.py
06_password_hashing.py — python source code from the python old learning materials (python_old/Cryptography/06_password_hashing.py).
Leer artículo →