From e4ecac4af9dff319ab972c15a07a5b72825f373c Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Mon, 31 Mar 2025 02:31:00 +0900 Subject: [PATCH 1/6] solve(w01): 1. Two Sum --- two-sum/jeongwoo903.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 two-sum/jeongwoo903.js diff --git a/two-sum/jeongwoo903.js b/two-sum/jeongwoo903.js new file mode 100644 index 000000000..9abecdf0d --- /dev/null +++ b/two-sum/jeongwoo903.js @@ -0,0 +1,20 @@ +/** + * @param {number[]} nums + * @param {number} target + * @return {number[]} + */ +var twoSum = function(nums, target) { + const numMap = new Map(); + + for (let i= 0 ; i < nums.length ; i++ ) { + let complement = target - nums[i]; + + if (numMap.has(complement)) { + return [numMap.get(complement), i]; + } + + numMap.set(nums[i], i); + } + + return []; +}; \ No newline at end of file From 4ca4b9187d7eec8e2ede6c771f79e0c7ff15e36e Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Mon, 31 Mar 2025 02:41:51 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=EC=A4=84=EB=B0=94=EA=BF=88=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/jeongwoo903.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/jeongwoo903.js b/two-sum/jeongwoo903.js index 9abecdf0d..1144c727a 100644 --- a/two-sum/jeongwoo903.js +++ b/two-sum/jeongwoo903.js @@ -17,4 +17,4 @@ var twoSum = function(nums, target) { } return []; -}; \ No newline at end of file +}; From 6ca4f608b67adfb4eb1570bae192c31b3fdd4b80 Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Mon, 31 Mar 2025 13:33:46 +0900 Subject: [PATCH 3/6] solve(w01): 347. Top K Frequent Elements --- top-k-frequent-elements/jeongwoo903.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 top-k-frequent-elements/jeongwoo903.js diff --git a/top-k-frequent-elements/jeongwoo903.js b/top-k-frequent-elements/jeongwoo903.js new file mode 100644 index 000000000..97f1232bb --- /dev/null +++ b/top-k-frequent-elements/jeongwoo903.js @@ -0,0 +1,20 @@ +/** + * @param {number[]} nums + * @param {number} k + * @return {number[]} + */ +var topKFrequent = function(nums, k) { + // Map을 통해 nums의 담긴 숫자들의 빈번함을 정리함. + const frequencyMap = nums.reduce((map, num) => { + map.set(num, (map.get(num) || 0) + 1); + return map; + }, new Map()); + + // 빈도수를 기준으로 정렬하여 답을 유도함. + const result = Array.from(frequencyMap.entries()) + .sort((a, b) => b[1] - a[1]) + .slice(0, k) + .map(item => item[0]); + + return result; +}; From 83d3346c463567c6492dcf902aa1f82cd9b09635 Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Tue, 1 Apr 2025 23:03:34 +0900 Subject: [PATCH 4/6] solve(w01): 128. Longest Consecutive Sequence --- longest-consecutive-sequence/jeongwoo903.js | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 longest-consecutive-sequence/jeongwoo903.js diff --git a/longest-consecutive-sequence/jeongwoo903.js b/longest-consecutive-sequence/jeongwoo903.js new file mode 100644 index 000000000..06f390ae3 --- /dev/null +++ b/longest-consecutive-sequence/jeongwoo903.js @@ -0,0 +1,25 @@ +/** + * @param {number[]} nums + * @return {number} + */ + +var longestConsecutive = function(nums) { + if (nums.length <= 1) return nums.length; + + const sortedArray = [...new Set(nums)].sort((a,b) => a - b); + + let maxLength = 1; + let currentLength = 1; + + for (let i = 1; i < sortedArray.length; i++) { + if (sortedArray[i] === sortedArray[i-1] + 1) { + currentLength++; + } else { + currentLength = 1; + } + + maxLength = Math.max(maxLength, currentLength); + } + + return maxLength; +}; From 27b0a933c66675c7767a766cd1c5d1b5455092a2 Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Wed, 2 Apr 2025 23:54:19 +0900 Subject: [PATCH 5/6] solve(w01): 217. Contains Duplicate --- contains-duplicate/jeongwoo903.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 contains-duplicate/jeongwoo903.js diff --git a/contains-duplicate/jeongwoo903.js b/contains-duplicate/jeongwoo903.js new file mode 100644 index 000000000..8454779c6 --- /dev/null +++ b/contains-duplicate/jeongwoo903.js @@ -0,0 +1,11 @@ +/** + * @param {number[]} nums + * @return {boolean} + */ + +var containsDuplicate = function(nums) { + const originalLength = nums.length; + const parsedLength = new Set(nums).size; + + return originalLength !== parsedLength; +}; From 054993d4afbcaeeef2dace10ffede598606af09d Mon Sep 17 00:00:00 2001 From: jeongwoo903 Date: Fri, 4 Apr 2025 01:21:55 +0900 Subject: [PATCH 6/6] solve(w01): 198. House Robber --- house-robber/jeongwoo903.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 house-robber/jeongwoo903.js diff --git a/house-robber/jeongwoo903.js b/house-robber/jeongwoo903.js new file mode 100644 index 000000000..b94456ab3 --- /dev/null +++ b/house-robber/jeongwoo903.js @@ -0,0 +1,19 @@ +/** + * @param {number[]} nums + * @return {number} + */ + +// dp 개념을 이용 + +var rob = function(nums) { + if(nums.length == 0) { return 0 }; + if(nums.length == 1) { return nums[0] }; + + nums[1] = Math.max(nums[0], nums[1]); + + for(let i = 2; i < nums.length; i++) { + nums[i] = Math.max(nums[i-2] + nums[i], nums[i-1]) + } + + return nums[nums.length - 1]; +};