diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/121. Best Time to Buy and Sell Stock.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/121. Best Time to Buy and Sell Stock.py" new file mode 100644 index 00000000..848c9133 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/121. Best Time to Buy and Sell Stock.py" @@ -0,0 +1,14 @@ +class Solution: + def maxProfit(self, prices: list[int]) -> int: + buy = float('inf') + sell = 0 + ans = 0 + for price in prices: + if price < buy: + buy = price + sell = price + + sell = max(sell, price) + ans = max(ans, sell-buy) + + return ans