best time to buy and sell stock1 [Leetcode][자바스크립트][Easy] 121. Best Time to Buy and Sell Stock 풀이 /** * 121_BestTimeToBuyAndSellStock.js * Easy * https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ */ var maxProfit = function(prices) { let currMin = prices[0], currMax = 0, _maxProfit = 0; prices.forEach((price) => { if (price > currMax) { currMax = price; _maxProfit = Math.max(_maxProfit, currMax - currMin); } if (price currMin) _maxProfit = Math.max(.. 2022. 1. 8. 이전 1 다음