From 44faa333c57685e6d565509ad096dcb26429eeb7 Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:19:06 +0900 Subject: [PATCH] Create 121. Best Time to Buy and Sell Stock.py --- .../121. Best Time to Buy and Sell Stock.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/121. Best Time to Buy and Sell Stock.py" 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