From a376b55aca2cdf950b930e391ce127e989108280 Mon Sep 17 00:00:00 2001 From: grapefruit Date: Mon, 2 Mar 2026 18:09:32 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20containsDuplicate=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/grapefruit13.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contains-duplicate/grapefruit13.ts diff --git a/contains-duplicate/grapefruit13.ts b/contains-duplicate/grapefruit13.ts new file mode 100644 index 0000000000..c98219cbf3 --- /dev/null +++ b/contains-duplicate/grapefruit13.ts @@ -0,0 +1,16 @@ +/** + * @description nums 배열에서 중복 숫자 확인 + * @param nums - 숫자 배열 + * @returns boolean - 중복 숫자 여부 + */ +const containsDuplicate = (nums: number[]) => { + const hasSeen = new Set(); + + for (const num of nums) { + if (hasSeen.has(num)) { + return true; + } + hasSeen.add(num); + } + return false; +}; From 6b3390ed15dfe1418819674246849742e00724ad Mon Sep 17 00:00:00 2001 From: grapefruit Date: Mon, 2 Mar 2026 18:53:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20two=20sum=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- two-sum/grapefruit13.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 two-sum/grapefruit13.ts diff --git a/two-sum/grapefruit13.ts b/two-sum/grapefruit13.ts new file mode 100644 index 0000000000..42ca5315b8 --- /dev/null +++ b/two-sum/grapefruit13.ts @@ -0,0 +1,18 @@ +/** + * @description nums 배열에서 두 수를 더해 target을 만족하는 인덱스를 반환 + * @param {number[]} nums - 숫자 배열 + * @param {number} target - 목표 숫자 + * @return {number[]} - 두 수의 인덱스 + */ +var twoSum = function (nums, target) { + const map = new Map(); + + for (let i = 0; i < nums.length; i++) { + const current = nums[i]; + const needed = target - current; + if (map.has(needed)) { + return [map.get(needed), i]; + } + map.set(current, i); + } +};