From 1ce733b8a1906fa115c9119fd7c5f08e2dc1bb5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 20 Aug 2025 09:34:26 +0900 Subject: [PATCH 1/2] best-time-to-buy-and-sell-stock --- best-time-to-buy-and-sell-stock/jun0811.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/jun0811.js diff --git a/best-time-to-buy-and-sell-stock/jun0811.js b/best-time-to-buy-and-sell-stock/jun0811.js new file mode 100644 index 000000000..e2e41c5bf --- /dev/null +++ b/best-time-to-buy-and-sell-stock/jun0811.js @@ -0,0 +1,11 @@ +var maxProfit = function (prices) { + let minPrice = prices[0]; + let maxProfit = 0; + + for (let i = 1; i < prices.length; i++) { + minPrice = Math.min(minPrice, prices[i]); + maxProfit = Math.max(maxProfit, prices[i] - minPrice); + } + + return maxProfit; +}; From e1ae708b945c1c875a564df57427c1d0ecba1ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Wed, 20 Aug 2025 09:34:34 +0900 Subject: [PATCH 2/2] group-anagrams --- group-anagrams/jun0811.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 group-anagrams/jun0811.js diff --git a/group-anagrams/jun0811.js b/group-anagrams/jun0811.js new file mode 100644 index 000000000..26275e077 --- /dev/null +++ b/group-anagrams/jun0811.js @@ -0,0 +1,21 @@ +/** + * @param {string[]} strs + * @return {string[][]} + */ +var groupAnagrams = function (strs) { + const hashMap = new Map(); + const res = []; + strs.forEach((str, index) => { + const sortedStr = [...str].sort().join(''); + if (hashMap.has(sortedStr)) { + hashMap.set(sortedStr, [...hashMap.get(sortedStr), index]); + } else { + hashMap.set(sortedStr, [index]); + } + }); + for (const [key, values] of hashMap) { + const anagrams = values.map((v) => strs[v]); + res.push(anagrams); + } + return res; +};