From dc7d76d6c256306518852b86d1d900d9cd09c87b Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Sun, 27 Jul 2025 10:15:51 +0900 Subject: [PATCH 1/5] valid-anagram --- valid-anagram/sooooo-an.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 valid-anagram/sooooo-an.ts diff --git a/valid-anagram/sooooo-an.ts b/valid-anagram/sooooo-an.ts new file mode 100644 index 000000000..985be9505 --- /dev/null +++ b/valid-anagram/sooooo-an.ts @@ -0,0 +1,18 @@ +function isAnagram(s: string, t: string): boolean { + if (s.length !== t.length) return false; + + const objS: { [key: string]: number } = {}; + + for (const str of s) { + objS[str] = (objS[str] ?? 0) + 1; + } + + for (const str of t) { + if (!objS[str]) { + return false; + } + objS[str]--; + } + + return true; +} From 54bc2e15e6b67253ab1181c19964f29ffb2585d1 Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Sun, 27 Jul 2025 10:41:15 +0900 Subject: [PATCH 2/5] climbing-stairs --- climbing-stairs/sooooo-an.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 climbing-stairs/sooooo-an.ts diff --git a/climbing-stairs/sooooo-an.ts b/climbing-stairs/sooooo-an.ts new file mode 100644 index 000000000..716520185 --- /dev/null +++ b/climbing-stairs/sooooo-an.ts @@ -0,0 +1,19 @@ +function climbStairs(n: number): number { + type Cache = { [key: number]: number }; + + const cache: Cache = { + 2: 2, + 1: 1, + }; + + const fibonacci = (n: number, cache: Cache) => { + if (n in cache) { + return cache[n]; + } else { + cache[n] = fibonacci(n - 2, cache) + fibonacci(n - 1, cache); + return cache[n]; + } + }; + + return fibonacci(n, cache); +} From 03c0ff6a04be121da88cdb6f323614783a02bf9d Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Wed, 30 Jul 2025 22:08:38 +0900 Subject: [PATCH 3/5] 3sum --- 3sum/sooooo-an.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 3sum/sooooo-an.ts diff --git a/3sum/sooooo-an.ts b/3sum/sooooo-an.ts new file mode 100644 index 000000000..4570b4e9c --- /dev/null +++ b/3sum/sooooo-an.ts @@ -0,0 +1,30 @@ +function threeSum(nums: number[]): number[][] { + nums.sort((a: number, b: number) => a - b); + const results: [number, number, number][] = []; + + for (let i = 0; i < nums.length - 2; i++) { + if (i > 0 && nums[i] === nums[i - 1]) continue; + + let left = i + 1; + let right = nums.length - 1; + + while (left < right) { + const current = nums[i] + nums[left] + nums[right]; + if (current === 0) { + results.push([nums[i], nums[left], nums[right]]); + + while (left < right && nums[left] === nums[left + 1]) left++; + while (left < right && nums[right] === nums[right - 1]) right--; + + left++; + right--; + } else if (current < 0) { + left++; + } else if (current > 0) { + right--; + } + } + } + + return results; +} From df0f5843ce4e7086cdd7897ea7835106059630b7 Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Thu, 31 Jul 2025 21:18:46 +0900 Subject: [PATCH 4/5] product-of-array-except-self --- product-of-array-except-self/sooooo-an.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 product-of-array-except-self/sooooo-an.ts diff --git a/product-of-array-except-self/sooooo-an.ts b/product-of-array-except-self/sooooo-an.ts new file mode 100644 index 000000000..e3816d178 --- /dev/null +++ b/product-of-array-except-self/sooooo-an.ts @@ -0,0 +1,18 @@ +function productExceptSelf(nums: number[]): number[] { + const results = []; + + let left = 1; + let right = 1; + + for (let i = 0; i < nums.length; i++) { + results[i] = left; + left *= nums[i]; + } + + for (let i = nums.length - 1; i >= 0; i--) { + results[i] *= right; + right *= nums[i]; + } + + return results; +} From 32633cc35086c2bfbec8b80b1691fc4e16a02bdc Mon Sep 17 00:00:00 2001 From: sooooo-an Date: Thu, 31 Jul 2025 21:47:44 +0900 Subject: [PATCH 5/5] validate-binary-search-tree --- validate-binary-search-tree/sooooo-an.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 validate-binary-search-tree/sooooo-an.ts diff --git a/validate-binary-search-tree/sooooo-an.ts b/validate-binary-search-tree/sooooo-an.ts new file mode 100644 index 000000000..b0ab1f9f5 --- /dev/null +++ b/validate-binary-search-tree/sooooo-an.ts @@ -0,0 +1,18 @@ +function isValidBST(root: TreeNode | null): boolean { + return validateBSTHelper(root, -Infinity, Infinity); +} + +const validateBSTHelper = ( + root: TreeNode | null, + minValue: number, + maxValue: number +): boolean => { + if (root === null) { + return true; + } + if (root.val <= minValue || root.val >= maxValue) { + return false; + } + const leftIsValid = validateBSTHelper(root.left, minValue, root.val); + return leftIsValid && validateBSTHelper(root.right, root.val, maxValue); +};