From 56665a74ce0555e2516c0ab43053718d8ce21f77 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Mon, 31 Aug 2026 23:52:42 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=A7=84=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../121. Best Time to Buy and Sell Stock.java" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" new file mode 100644 index 00000000..8918570a --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/121. Best Time to Buy and Sell Stock.java" @@ -0,0 +1,13 @@ +class Solution { + public int maxProfit(int[] prices) { + int minPrice = Integer.MAX_VALUE; + int maxProfit = 0; + + for (int price : prices) { + if (price < minPrice) minPrice = price; + else if (price - minPrice > maxProfit) maxProfit = price - minPrice; + } + + return maxProfit; + } +} \ No newline at end of file