Best Stock Profit
Imagine a stock price chart where you may choose one day to buy and a later day to sell. Given a list prices, where prices[i] is the price on day i, find the maximum profit you can make with one transaction. If no profit 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: list[int]) -> int:
Теги
arraydp
Prijavite se za ogled zgodovine oddaj
PrijavaPrijavite se za uporabo mentorja UI
PrijavaVisible 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
[3,3,3]Expected
06
Input
[8,2,6,4,7,5]Expected
5Focus radio
Paused · SomaFM · Fluid