From c62e032ae172674c7970f126d18d4eda618d24e6 Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Tue, 5 Aug 2025 18:10:44 +0900 Subject: [PATCH 1/5] valid palindrome solution --- valid-palindrome/yhkee0404.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 valid-palindrome/yhkee0404.ts diff --git a/valid-palindrome/yhkee0404.ts b/valid-palindrome/yhkee0404.ts new file mode 100644 index 000000000..7f23194b3 --- /dev/null +++ b/valid-palindrome/yhkee0404.ts @@ -0,0 +1,19 @@ +function isPalindrome(s: string): boolean { + const isAlpha = x => x.toLowerCase() >= 'a' && x.toLowerCase() <= 'z'; + const isNumeric = x => x >= '0' && x <= '9'; + const isAlphanumeric = x => isAlpha(x) || isNumeric(x); + let i = 0, j = s.length - 1; + while (i < j) { + while (i !== j && ! isAlphanumeric(s[i])) { + i++; + } + while (i !== j && ! isAlphanumeric(s[j])) { + j--; + } + if (s[i].toLowerCase() !== s[j].toLowerCase()) { + return false; + } + i++, j--; + } + return true; +}; From cfb7db62a807ac623e2e414ab0343b99a708fabf Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Sat, 9 Aug 2025 21:24:13 +0900 Subject: [PATCH 2/5] number of 1 bits solution --- number-of-1-bits/yhkee0404.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 number-of-1-bits/yhkee0404.py diff --git a/number-of-1-bits/yhkee0404.py b/number-of-1-bits/yhkee0404.py new file mode 100644 index 000000000..74c6bcbca --- /dev/null +++ b/number-of-1-bits/yhkee0404.py @@ -0,0 +1,4 @@ +class Solution: + @lru_cache + def hammingWeight(self, n: int) -> int: + return 1 + self.hammingWeight(n - (n & - n)) if n else 0 From 84495245374cb45436b809c52a4b3ee76ff04916 Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Sat, 9 Aug 2025 23:21:05 +0900 Subject: [PATCH 3/5] combination sum solution --- combination-sum/yhkee0404.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 combination-sum/yhkee0404.ts diff --git a/combination-sum/yhkee0404.ts b/combination-sum/yhkee0404.ts new file mode 100644 index 000000000..7caf9243d --- /dev/null +++ b/combination-sum/yhkee0404.ts @@ -0,0 +1,24 @@ +function combinationSum(candidates: number[], target: number, dp = new Map()): number[][] { + if (target <= 0) { + return []; + } + let ans = dp.get(target); + if (ans !== undefined) { + return ans; + } + ans = []; + for (const candidate of candidates) { + if (target == candidate) { + ans.push([candidate]); + continue; + } + for (const combination of combinationSum(candidates, target - candidate, dp)) { + if (combination[combination.length - 1] > candidate) { + continue; + } + ans.push([...combination, candidate]); + } + } + dp.set(target, ans); + return ans; +}; From 8468fd17efc31c3ee61c842f2f457878d93e58b7 Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Sat, 9 Aug 2025 23:58:10 +0900 Subject: [PATCH 4/5] decode ways solution --- decode-ways/yhkee0404.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 decode-ways/yhkee0404.go diff --git a/decode-ways/yhkee0404.go b/decode-ways/yhkee0404.go new file mode 100644 index 000000000..f0d3a67a2 --- /dev/null +++ b/decode-ways/yhkee0404.go @@ -0,0 +1,20 @@ +func numDecodings(s string) int { + dp := make([]int, len(s) + 1) + dp[0] = 1 + const cnt = rune('Z') - rune('A') + 1 + for i, c := range s { + a := 0 + if i != 0 { + b := (rune(s[i - 1]) - rune('0')) * 10 + rune(c) - rune('0') + if b > 9 && b <= cnt { + a += dp[i - 1] + } + } + b := rune(c) - rune('0') + if b != 0 && b < cnt { + a += dp[i] + } + dp[i + 1] = a + } + return dp[len(s)] +} From 87da9b6db48f37cd4bda21c8b29d88a0d1b79419 Mon Sep 17 00:00:00 2001 From: yhkee0404 Date: Sun, 10 Aug 2025 01:38:34 +0900 Subject: [PATCH 5/5] maximum subarray solution --- maximum-subarray/yhkee0404.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 maximum-subarray/yhkee0404.rs diff --git a/maximum-subarray/yhkee0404.rs b/maximum-subarray/yhkee0404.rs new file mode 100644 index 000000000..20fabda3d --- /dev/null +++ b/maximum-subarray/yhkee0404.rs @@ -0,0 +1,35 @@ +impl Solution { + pub fn max_sub_array(nums: Vec) -> i32 { + return Self::solve(&nums, 0, nums.len()).unwrap_or(0); + } + fn solve(nums: &Vec, l: usize, r: usize) -> Option { + if l >= r { + return None + } + if l + 1 == r { + return Some(nums[l]) + } + let mid = l + ((r - l) >> 1); + let a = Self::solve(nums, l, mid); + let b = Self::solve(nums, mid, r); + if a.is_none() || b.is_none() { + return a.or(b) + } + let mut ans = a.max(b); + let mut c = 0; + let mut d = 0; + for i in (l..mid).rev() { + c += nums[i]; + d = d.max(c); + } + if d == 0 { + return ans + } + c = d; + for i in mid..r { + c += nums[i]; + d = d.max(c); + } + ans.max(Some(d)) + } +}