Best Stock Profit
The list prices stores a stock price for each day, and you may make exactly one buy and one sell. You must buy first and sell on a later day. Given prices, return the maximum profit you can make. If no profitable trade is possible, return 0.
Примеры
Ввод
[7, 1, 5, 3, 6, 4]Вывод
5Ввод
[7, 6, 4, 3, 1]Вывод
0Ввод
[1, 2, 3, 4, 5]Вывод
4Нужно реализовать
def max_profit(prices):
Теги
arraydp
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
[7,1,5,3,6,4]Expected
52
Input
[7,6,4,3,1]Expected
03
Input
[1,2,3,4,5]Expected
44
Input
[2,4,1]Expected
25
Input
[]Expected
06
Input
[3]Expected
0Focus radio
Paused · SomaFM · Fluid