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