From e1d577331af05440839203a66415034ed79efba5 Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Tue, 3 Mar 2026 15:37:52 +0900 Subject: [PATCH 1/6] add: contains duplicate solution --- contains-duplicate/Cyjin-jani.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 contains-duplicate/Cyjin-jani.js diff --git a/contains-duplicate/Cyjin-jani.js b/contains-duplicate/Cyjin-jani.js new file mode 100644 index 0000000000..304b042b68 --- /dev/null +++ b/contains-duplicate/Cyjin-jani.js @@ -0,0 +1,4 @@ +const containsDuplicate = function (nums) { + const data = new Set(nums); + return data.size !== nums.length; +}; From f3ef8527d441fa354c04e80d8923266a511d8a08 Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Tue, 3 Mar 2026 15:38:01 +0900 Subject: [PATCH 2/6] add: two sum solution --- two-sum/Cyjin-jani.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 two-sum/Cyjin-jani.js diff --git a/two-sum/Cyjin-jani.js b/two-sum/Cyjin-jani.js new file mode 100644 index 0000000000..a450ae29d8 --- /dev/null +++ b/two-sum/Cyjin-jani.js @@ -0,0 +1,14 @@ +const twoSum = function (nums, target) { + let memo = {}; + + for (let i = 0; i < nums.length; i++) { + let current = nums[i]; + let needed = target - current; + + if (needed in memo) { + return [memo[needed], i]; + } + + memo[current] = i; + } +}; From ff227d757def296cd5bfc1737da36d06ad976a08 Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Thu, 5 Mar 2026 17:28:43 +0900 Subject: [PATCH 3/6] add: topKFrequentElements solution --- top-k-frequent-elements/Cyjin-jani.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 top-k-frequent-elements/Cyjin-jani.js diff --git a/top-k-frequent-elements/Cyjin-jani.js b/top-k-frequent-elements/Cyjin-jani.js new file mode 100644 index 0000000000..0218469ba2 --- /dev/null +++ b/top-k-frequent-elements/Cyjin-jani.js @@ -0,0 +1,16 @@ +const topKFrequent = function (nums, k) { + const tempArr = Array.from({ length: nums.length }, () => []); + const obj = {}; + + for (let num of nums) { + obj[num] = (obj[num] || 0) + 1; + } + + for (let key in obj) { + const val = obj[key] - 1; + tempArr[val].push(+key); + } + + const answer = tempArr.flat(); + return answer.slice(-k); +}; From e0d74da94954b912cf62bf99fcb94306e32199d3 Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Fri, 6 Mar 2026 15:14:58 +0900 Subject: [PATCH 4/6] add: longestConsecutiveSequence solution --- longest-consecutive-sequence/Cyjin-jani.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 longest-consecutive-sequence/Cyjin-jani.js diff --git a/longest-consecutive-sequence/Cyjin-jani.js b/longest-consecutive-sequence/Cyjin-jani.js new file mode 100644 index 0000000000..fc730e379f --- /dev/null +++ b/longest-consecutive-sequence/Cyjin-jani.js @@ -0,0 +1,22 @@ +var longestConsecutive = function (nums) { + // 숫자 존재 유무를 확인할 수 있는 자료구조 세팅 + const dataSet = new Set(nums); + let answer = 0; + + // 전체 숫자를 순회하면서 시작점을 확인 + for (let num of dataSet) { + // num - 1이 dataSet에 있는지 확인. 있다면 시작점이 아니므로 패스 + if (!dataSet.has(num - 1)) { + // 없다면 시작점. 여기서부터 연속된 숫자가 얼마나 있는지 카운팅. + let count = 1; + let target = num; + while (dataSet.has(target + 1)) { + count++; + target++; + } + // longest를 구하는 문제이므로 max로 더 긴 답을 판단 + answer = Math.max(count, answer); + } + } + return answer; +}; From 6cd8ee97be0ad9b4108160e8b2f64b815649de8d Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Fri, 6 Mar 2026 15:41:10 +0900 Subject: [PATCH 5/6] add: houseRobber solution --- house-robber/Cyjin-jani.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 house-robber/Cyjin-jani.js diff --git a/house-robber/Cyjin-jani.js b/house-robber/Cyjin-jani.js new file mode 100644 index 0000000000..53270e3b76 --- /dev/null +++ b/house-robber/Cyjin-jani.js @@ -0,0 +1,11 @@ +const rob = function (nums) { + // 최대 누적값을 저장하는 배열 + const data = []; + data[0] = nums[0]; + + for (let i = 1; i < nums.length; i++) { + data[i] = Math.max(data[i - 1], (data[i - 2] ?? 0) + nums[i]); + } + + return data[data.length - 1]; +}; From 7bdd0d1b59fc69985a8b1daae16a0212ccc2beb0 Mon Sep 17 00:00:00 2001 From: Cyjin-jani Date: Fri, 6 Mar 2026 15:57:12 +0900 Subject: [PATCH 6/6] =?UTF-8?q?update:=20topKFrequentElements=20solution?= =?UTF-8?q?=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- top-k-frequent-elements/Cyjin-jani.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/top-k-frequent-elements/Cyjin-jani.js b/top-k-frequent-elements/Cyjin-jani.js index 0218469ba2..7c1a2d8813 100644 --- a/top-k-frequent-elements/Cyjin-jani.js +++ b/top-k-frequent-elements/Cyjin-jani.js @@ -11,6 +11,13 @@ const topKFrequent = function (nums, k) { tempArr[val].push(+key); } - const answer = tempArr.flat(); - return answer.slice(-k); + // answer.flat(), return answer.slice(-k) 대신 좀 더 최적화된 코드로 변경합니다. + const answer = []; + for (let i = tempArr.length - 1; i >= 0; i--) { + for (let num of tempArr[i]) { + answer.push(num); + if (answer.length === k) return answer; + } + } + return answer; };