From 38c6add580f72a5d90eeb374035be103946137d5 Mon Sep 17 00:00:00 2001 From: mike2ox <firefinger07@gmail.com> Date: Sat, 21 Dec 2024 20:12:04 +0900 Subject: [PATCH 1/3] feat: Upload valid-anagram(typescript) --- valid-anagram/mike2ox.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 valid-anagram/mike2ox.ts diff --git a/valid-anagram/mike2ox.ts b/valid-anagram/mike2ox.ts new file mode 100644 index 000000000..773b06c72 --- /dev/null +++ b/valid-anagram/mike2ox.ts @@ -0,0 +1,4 @@ +function isAnagram(s: string, t: string): boolean { + if (s.length !== t.length) return false; + return s.split("").sort().join() === t.split("").sort().join(); +} From 3ea4c372c5d80ebecb1965a59a270472e7243c97 Mon Sep 17 00:00:00 2001 From: mike2ox <firefinger07@gmail.com> Date: Sat, 21 Dec 2024 20:24:08 +0900 Subject: [PATCH 2/3] feat: Upload climbing-stairs(typescript) --- climbing-stairs/mike2ox.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 climbing-stairs/mike2ox.ts diff --git a/climbing-stairs/mike2ox.ts b/climbing-stairs/mike2ox.ts new file mode 100644 index 000000000..9c485ef68 --- /dev/null +++ b/climbing-stairs/mike2ox.ts @@ -0,0 +1,12 @@ +function climbStairs(n: number): number { + let result = 0; + let step1 = 1; + let step2 = 0; + + for (let i = 0; i < n; i++) { + result = step1 + step2; + step2 = step1; + step1 = result; + } + return result; +} From 5823714fd2cfc61598b70637c465ec4cda4e1bda Mon Sep 17 00:00:00 2001 From: mike2ox <firefinger07@gmail.com> Date: Sat, 21 Dec 2024 21:37:50 +0900 Subject: [PATCH 3/3] feat: Upload 3sum(typescript) --- 3sum/mike2ox.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 3sum/mike2ox.ts diff --git a/3sum/mike2ox.ts b/3sum/mike2ox.ts new file mode 100644 index 000000000..56a714282 --- /dev/null +++ b/3sum/mike2ox.ts @@ -0,0 +1,42 @@ +function threeSum(nums: number[]): number[][] { + if (nums.length < 3) return []; + const result: number[][] = []; + const checked = new Set<string>(); + const numMap = new Map<number, number>(); + + // 중복 결과 방지 + nums.sort((a, b) => a - b); + // Map에 모든 값과 인덱스 저장 + nums.forEach((num, index) => numMap.set(num, index)); + + for (let i = 0; i < nums.length - 2; i++) { + if (nums[i] > 0) break; // 양수면 존재 X + // 중복된 첫 번째 수 건너뛰기 + if (i > 0 && nums[i] === nums[i - 1]) continue; + + for (let j = i + 1; j < nums.length - 1; j++) { + // 중복된 두 번째 수 건너뛰기 + if (j > i + 1 && nums[j] === nums[j - 1]) continue; + // 세 번째 수 계산 + const target = -(nums[i] + nums[j]); + + // Map을 사용하여 세 번째 수 검색 + if (numMap.has(target)) { + const k = numMap.get(target)!; + if (k > j) { + // k가 j보다 커야 중복 방지 + const triplet = [nums[i], nums[j], nums[k]]; + const key = triplet.join(","); + + // Set을 사용하여 중복 결과 방지 + if (!checked.has(key)) { + checked.add(key); + result.push(triplet); + } + } + } + } + } + + return result; +}