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 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