From 79b416983c7d0d5a1366b51b7bbeabac2dca6daf Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 5 Mar 2026 02:16:37 +0900 Subject: [PATCH 1/5] contains-duplicate --- contains-duplicate/nowrobin.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contains-duplicate/nowrobin.js diff --git a/contains-duplicate/nowrobin.js b/contains-duplicate/nowrobin.js new file mode 100644 index 000000000..d8de04178 --- /dev/null +++ b/contains-duplicate/nowrobin.js @@ -0,0 +1,9 @@ +/** + * @param {number[]} nums + * @return {boolean} + */ +var containsDuplicate = function(nums) { + return new Set(nums).size != nums.length; +}; + +// 40ms 80.33MB \ No newline at end of file From e77dac39ad6a60c3adb1ee0102390d53ce03fdc8 Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 5 Mar 2026 18:23:40 +0900 Subject: [PATCH 2/5] two sum solution --- contains-duplicate/nowrobin.js | 2 +- two-sum/nowrobin.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 two-sum/nowrobin.js diff --git a/contains-duplicate/nowrobin.js b/contains-duplicate/nowrobin.js index d8de04178..3616b02da 100644 --- a/contains-duplicate/nowrobin.js +++ b/contains-duplicate/nowrobin.js @@ -6,4 +6,4 @@ var containsDuplicate = function(nums) { return new Set(nums).size != nums.length; }; -// 40ms 80.33MB \ No newline at end of file +// 40ms 80.33MB diff --git a/two-sum/nowrobin.js b/two-sum/nowrobin.js new file mode 100644 index 000000000..9dba294f1 --- /dev/null +++ b/two-sum/nowrobin.js @@ -0,0 +1,17 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number[]} + */ + +// 34ms 54mb +var twoSum = function(nums, target) { + for (let i = 0; i < nums.length; i++) { + for (let j = i + 1; j < nums.length; j++) { + if (nums[j] === target - nums[i]) { + return [i, j]; + } + } + } + return [] +}; From a230dabeb922ff1c16436ad249408f90100f5ac5 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 7 Mar 2026 18:27:50 +0900 Subject: [PATCH 3/5] Solution: House-robber --- house-robber/nowrobin.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 house-robber/nowrobin.js diff --git a/house-robber/nowrobin.js b/house-robber/nowrobin.js new file mode 100644 index 000000000..6ca2402f0 --- /dev/null +++ b/house-robber/nowrobin.js @@ -0,0 +1,35 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var rob = function(nums) { + // 집의 개수 + const n = nums.length; + + // 집이 하나뿐이면 그 집을 터는 것이 최대값 + if (n === 1) { + return nums[0]; + } + + // dp[i] = 0번 집부터 i번 집까지 고려했을 때 훔칠 수 있는 최대 금액 + const dp = Array(n).fill(0); + + // 첫 번째 집까지의 최대 금액 + dp[0] = nums[0]; + + // 두 번째 집까지의 최대 금액 + // 두 집은 동시에 털 수 없으므로 둘 중 큰 값을 선택 + dp[1] = Math.max(nums[0], nums[1]); + + // 세 번째 집부터 마지막 집까지 반복 + for (let i = 2; i < n; i++) { + + // 두 가지 선택지 중 더 큰 값을 선택 + // 1️⃣ 현재 집을 털지 않는다 → 이전 집까지의 최대 금액(dp[i-1]) + // 2️⃣ 현재 집을 턴다 → 전전 집까지의 최대 금액(dp[i-2]) + 현재 집 돈(nums[i]) + dp[i] = Math.max(dp[i - 1], nums[i] + dp[i - 2]); + } + + // 마지막 집까지 고려했을 때의 최대 금액 반환 + return dp[n - 1]; +}; From 92538170d28d88456a51ecfe9b563134825d32d9 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 7 Mar 2026 18:28:14 +0900 Subject: [PATCH 4/5] Solution: Longest-consecutive-sequence --- longest-consecutive-sequence/nowrobin.js | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 longest-consecutive-sequence/nowrobin.js diff --git a/longest-consecutive-sequence/nowrobin.js b/longest-consecutive-sequence/nowrobin.js new file mode 100644 index 000000000..6ce019324 --- /dev/null +++ b/longest-consecutive-sequence/nowrobin.js @@ -0,0 +1,35 @@ +/** + * 주어진 숫자 배열에서 가장 긴 연속된 수열의 길이를 찾는다. + * 시간복잡도: O(n) + * 이유: 각 숫자는 최대 한 번만 시작점으로 검사되고, + * 연속 수열 탐색도 중복 없이 진행된다. + * + * @param {number[]} nums + * @return {number} + */ +var longestConsecutive = function(nums) { + + // 배열을 Set으로 변환 + const numSet = new Set(nums); + + // 가장 긴 연속 길이를 저장 + let longest = 0; + // Set을 순회 + for (let n of numSet) { + // 현재 숫자가 연속 수열의 "시작점"인지 확인 + // n-1 이 존재하면 이미 앞에 전 수열 존재함 + if (!numSet.has(n - 1)) { + + // 시작하는 수열 길이 + let length = 1; + + // 계속 존재하는지 확인 + while (numSet.has(n + length)) { + length++; + } + // 지금까지 찾은 최대 길이 갱신 + longest = Math.max(longest, length); + } + } + return longest; +}; From f58aced03cc7d2dbe52e72de300e25992e775007 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 7 Mar 2026 18:28:35 +0900 Subject: [PATCH 5/5] Solution: top-k-frequent-elements --- top-k-frequent-elements/nowrobin.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 top-k-frequent-elements/nowrobin.js diff --git a/top-k-frequent-elements/nowrobin.js b/top-k-frequent-elements/nowrobin.js new file mode 100644 index 000000000..f26100f6b --- /dev/null +++ b/top-k-frequent-elements/nowrobin.js @@ -0,0 +1,19 @@ +/** + * @param {number[]} nums + * @param {number} k + * @return {number[]} + */ + +// 13ms 60mb +var topKFrequent = function(nums, k) { + let freq = new Map() + for(let i of nums){ + freq.set(i, (freq.get(i)|| 0) + 1 ) + } + const sorted = [...freq.entries()].sort((a, b) => b[1] - a[1]); + let result = [] + for (let j =0 ; j< k ; j++){ + result.push(sorted[j][0]) + } + return result +};