From 7697d5788afb26680389229f604d5023bde6647a Mon Sep 17 00:00:00 2001 From: dmswl6310 Date: Mon, 31 Aug 2026 20:59:33 +0900 Subject: [PATCH] 0831 --- .../121. Best Time to Buy and Sell Stock.js" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "leetcode3/\355\231\251\354\235\200\354\247\200/121. Best Time to Buy and Sell Stock.js" diff --git "a/leetcode3/\355\231\251\354\235\200\354\247\200/121. Best Time to Buy and Sell Stock.js" "b/leetcode3/\355\231\251\354\235\200\354\247\200/121. Best Time to Buy and Sell Stock.js" new file mode 100644 index 00000000..afbf84c9 --- /dev/null +++ "b/leetcode3/\355\231\251\354\235\200\354\247\200/121. Best Time to Buy and Sell Stock.js" @@ -0,0 +1,14 @@ +/** + * @param {number[]} prices + * @return {number} + */ +var maxProfit = function(prices) { + let max=0; + let maxProfit=0; + for(let i=prices.length-1;i>=0;i--){ + max=Math.max(max,prices[i]); + maxProfit=Math.max(maxProfit,max-prices[i]); + } + + return maxProfit; +}; \ No newline at end of file