Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 1.04 KB

_121. Best Time to Buy and Sell Stock.md

File metadata and controls

40 lines (28 loc) · 1.04 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 03, 2024

Last updated : July 03, 2024


Related Topics : Array, Dynamic Programming

Acceptance Rate : 54.57 %


Solutions

Python

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