upd
This commit is contained in:
12
algorithms/labs/lab8/code/greedy/1.py
Normal file
12
algorithms/labs/lab8/code/greedy/1.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def max_profit(prices):
|
||||
profit = 0
|
||||
for i in range(1, len(prices)):
|
||||
if prices[i] > prices[i - 1]:
|
||||
profit += prices[i] - prices[i - 1]
|
||||
return profit
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(max_profit([7, 1, 5, 3, 6, 4]))
|
||||
print(max_profit([1, 2, 3, 4, 5]))
|
||||
print(max_profit([7, 6, 4, 3, 1]))
|
||||
Reference in New Issue
Block a user