From adf541711850ce11784127d578ae48d6bcc915f9 Mon Sep 17 00:00:00 2001 From: B Date: Wed, 15 Jan 2025 23:44:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20place=20holder=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algorithms/removing-stars-from-a-string/dd_._._bb.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 algorithms/removing-stars-from-a-string/dd_._._bb.ts diff --git a/algorithms/removing-stars-from-a-string/dd_._._bb.ts b/algorithms/removing-stars-from-a-string/dd_._._bb.ts new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/algorithms/removing-stars-from-a-string/dd_._._bb.ts @@ -0,0 +1 @@ + \ No newline at end of file From 76fd64bb660903b06cf14459b5932644e7d25813 Mon Sep 17 00:00:00 2001 From: B Date: Thu, 16 Jan 2025 15:20:47 +0900 Subject: [PATCH 2/2] test: pull request action --- algorithms/two-sum/dd_._._bb.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/algorithms/two-sum/dd_._._bb.ts b/algorithms/two-sum/dd_._._bb.ts index c9c8000..12bf4cf 100644 --- a/algorithms/two-sum/dd_._._bb.ts +++ b/algorithms/two-sum/dd_._._bb.ts @@ -1,17 +1,19 @@ /** - * - * @param nums - * @param target - * @returns + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) */ -function twoSum(nums, target) { - const numMap = new Map(); +function twoSum(nums: number[], target: number): number[] { + const numMap = new Map(); + for (let i = 0; i < nums.length; i++) { const complement = target - nums[i]; + if (numMap.has(complement)) { - return [numMap.get(complement), i]; + return [numMap.get(complement)!, i]; } + numMap.set(nums[i], i); } + return []; } \ No newline at end of file