Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Stock Profit by PythonLearner
def stock_profit(stock: list[int]) -> int:
min_price = stock[0]
profit = 0
for price in stock[1:]:
profit = max(price - min_price, profit)
min_price = min(price, min_price)
return profit
print('Example:')
print(stock_profit([3,1,3,4,5,1]))
assert stock_profit([2, 3, 4, 5]) == 3
assert stock_profit([3, 1, 3, 4, 5, 1]) == 4
assert stock_profit([4, 3, 2, 1]) == 0
assert stock_profit([6, 2, 1, 2, 3, 2, 3, 4, 5, 4]) == 4
assert stock_profit([1, 1, 1, 2, 1, 1, 1]) == 1
assert stock_profit([4, 3, 2, 1, 2, 1, 2, 1]) == 1
assert stock_profit([1, 1, 1, 1]) == 0
print("You are the best broker here! Click 'Check' to earn cool rewards!")
Nov. 16, 2021
Comments: