diff --git a/best-time-to-buy-and-sell-stock/hozzijeong.js b/best-time-to-buy-and-sell-stock/hozzijeong.js new file mode 100644 index 0000000000..7aefae99bc --- /dev/null +++ b/best-time-to-buy-and-sell-stock/hozzijeong.js @@ -0,0 +1,19 @@ +/** + * @param {number[]} prices + * @return {number} + */ +var maxProfit = function(prices) { + let maxGap = 0; + + for(let i =0; i < prices.length; i++){ + const price = prices[i]; + const restList = prices.slice(i); + + const max = Math.max(...restList); + + maxGap = Math.max(max-price, maxGap) + } + + return maxGap +}; +