From baa48d80c3e81df7f7be03ad75823e745e87f648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Mon, 21 Jul 2025 11:35:01 +0900 Subject: [PATCH 1/7] contains-duplicate --- contains-duplicate/jun0811.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 contains-duplicate/jun0811.js diff --git a/contains-duplicate/jun0811.js b/contains-duplicate/jun0811.js new file mode 100644 index 000000000..0638676ea --- /dev/null +++ b/contains-duplicate/jun0811.js @@ -0,0 +1,18 @@ +/** + * @param {number[]} nums + * @return {boolean} + */ +var containsDuplicate = function (nums) { + const count = []; + let res = false; + + for (const num of nums) { + if (count[num]) { + res = true; + break; + } else { + count[num] = 1; + } + } + return res; +}; From 3cdb2262985abd4cf4da0440411cfb0f0870f6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Mon, 21 Jul 2025 14:11:16 +0900 Subject: [PATCH 2/7] number-of-1-bits --- number-of-1-bits/jun0811.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 number-of-1-bits/jun0811.js diff --git a/number-of-1-bits/jun0811.js b/number-of-1-bits/jun0811.js new file mode 100644 index 000000000..15d687543 --- /dev/null +++ b/number-of-1-bits/jun0811.js @@ -0,0 +1,12 @@ +/** + * @param {number} n + * @return {number} + */ +var hammingWeight = function (n) { + let res = 0; + while (n > 0) { + res += n & 1; + n = n >> 1; // 나누기 2 + } + return res; +}; From d6279dedec33d6f7e1c3f0b6c621e45ea8c87b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Mon, 21 Jul 2025 16:56:03 +0900 Subject: [PATCH 3/7] top k frequent elements --- top-k-frequent-elements/jun0811.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 top-k-frequent-elements/jun0811.js diff --git a/top-k-frequent-elements/jun0811.js b/top-k-frequent-elements/jun0811.js new file mode 100644 index 000000000..a5fcfca1e --- /dev/null +++ b/top-k-frequent-elements/jun0811.js @@ -0,0 +1,20 @@ +/** + * @param {number[]} nums + * @param {number} k + * @return {number[]} + */ +var topKFrequent = function (nums, k) { + const countMap = new Map(); + for (const num of nums) { + if (countMap.has(num)) { + countMap.set(num, countMap.get(num) + 1); + } else { + countMap.set(num, 1); + } + } + const countArr = [...countMap]; + countArr.sort((a, b) => b[1] - a[1]); + + const res = countArr.slice(0, k).map((count) => count[0]); + return res; +}; From 9418c8f7950daed0d78f3e43b61e410c503150ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Thu, 24 Jul 2025 15:11:34 +0900 Subject: [PATCH 4/7] two-sum --- two-sum/jun0811.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 two-sum/jun0811.js diff --git a/two-sum/jun0811.js b/two-sum/jun0811.js new file mode 100644 index 000000000..ab2082338 --- /dev/null +++ b/two-sum/jun0811.js @@ -0,0 +1,26 @@ +// Time Complexity : O(N^2) + +var twoSum = function (nums, target) { + const l = nums.length; + for (let i = 0; i < l; i++) { + for (let j = i + 1; j < l; j++) { + const value = nums[i] + nums[j]; + if (value == target) return [i, j]; + } + } +}; + +// Time Complexity : O(N) + +var twoSum = function (nums, target) { + const Map = {}; + + nums.forEach((num, idx) => { + Map[num] = idx; + }); + + for (const idx in nums) { + const value = target - nums[idx]; + if (Map[value] >= 0 && Map[value] != idx) return [+idx, Map[value]]; + } +}; From f477bbf42f43b39ff299d34fdf785da317c93786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=A4=80?= Date: Thu, 24 Jul 2025 17:44:16 +0900 Subject: [PATCH 5/7] longest-common-subsequence --- longest-common-subsequence/jun0811.js | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 longest-common-subsequence/jun0811.js diff --git a/longest-common-subsequence/jun0811.js b/longest-common-subsequence/jun0811.js new file mode 100644 index 000000000..a25b6077f --- /dev/null +++ b/longest-common-subsequence/jun0811.js @@ -0,0 +1,29 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var longestConsecutive = function (nums) { + const set = new Set(); + + // set 생성 : O(n) + for (const num of nums) { + set.add(num); + } + + let res = 0; + + // set 순회 : O(n) + for (const num of set) { + if (set.has(num - 1)) continue; + let tmp = 1; + let cur = num; + // While 루프 전체: O(n) + while (true) { + const v = (cur += 1); + if (set.has(v)) tmp += 1; + else break; + } + if (tmp > res) res = tmp; + } + return res; +}; From af0ff74555cfa1ceaace5aefd26f99dac91fde96 Mon Sep 17 00:00:00 2001 From: jun0811 Date: Sat, 26 Jul 2025 00:58:21 +0900 Subject: [PATCH 6/7] house-robber --- house-robber/jun0811.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 house-robber/jun0811.js diff --git a/house-robber/jun0811.js b/house-robber/jun0811.js new file mode 100644 index 000000000..d7dcee73c --- /dev/null +++ b/house-robber/jun0811.js @@ -0,0 +1,17 @@ +/** + * @param {number[]} nums + * @return {number} + */ +var rob = function(nums) { + const n = nums.length; + if (n === 1) return nums[0]; + if (n === 2) return Math.max(nums[0], nums[1]); + const dp = [nums[0],nums[1],nums[2] + nums[0]]; + + for(let i =3; i < n; i++) { + const tmp1 = dp[i-2] + nums[i] + const tmp2 = dp[i-3] + nums[i] + dp[i] = tmp1> tmp2 ? tmp1 : tmp2 + } + return dp[n-1] > dp[n-2] ? dp[n-1] : dp[n-2] +}; \ No newline at end of file From 416793ecaa79a62c74cd7135a5974745558cbd3c Mon Sep 17 00:00:00 2001 From: jun0811 Date: Sat, 26 Jul 2025 00:59:37 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=EB=9D=84=EC=96=B4=EC=93=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- house-robber/jun0811.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/house-robber/jun0811.js b/house-robber/jun0811.js index d7dcee73c..224af6ad1 100644 --- a/house-robber/jun0811.js +++ b/house-robber/jun0811.js @@ -14,4 +14,4 @@ var rob = function(nums) { dp[i] = tmp1> tmp2 ? tmp1 : tmp2 } return dp[n-1] > dp[n-2] ? dp[n-1] : dp[n-2] -}; \ No newline at end of file +};