All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 03, 2024
Last updated : July 03, 2024
Related Topics : Array, Dynamic Programming
Acceptance Rate : 54.57 %
class Solution:
def maxProfit(self, prices: List[int]) -> int:
output = 0
maxxPrice = prices[-1]
for price in reversed(prices) :
if price > maxxPrice :
maxxPrice = price
elif maxxPrice - price > output :
output = maxxPrice - price
return output