From 3673158373304cf2b49fdedf1ef4f969ab5a0d36 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA Date: Sun, 23 Nov 2025 19:04:13 +0900 Subject: [PATCH 1/3] [:solved] two problems --- number-of-1-bits/ppxyn1.py | 10 ++++++++++ valid-palindrome/ppxyn1.py | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 number-of-1-bits/ppxyn1.py create mode 100644 valid-palindrome/ppxyn1.py diff --git a/number-of-1-bits/ppxyn1.py b/number-of-1-bits/ppxyn1.py new file mode 100644 index 0000000000..3762a12b3e --- /dev/null +++ b/number-of-1-bits/ppxyn1.py @@ -0,0 +1,10 @@ +# idea: - + +from collections import Counter +class Solution: + def hammingWeight(self, n: int) -> int: + bits = bin(n).split('0b')[-1] + return Counter(bits)['1'] + + + diff --git a/valid-palindrome/ppxyn1.py b/valid-palindrome/ppxyn1.py new file mode 100644 index 0000000000..de738b8ed0 --- /dev/null +++ b/valid-palindrome/ppxyn1.py @@ -0,0 +1,11 @@ +# idea : regex +import re + +class Solution: + def isPalindrome(self, s: str) -> bool: + alphabet = re.sub(r'[^A-Za-z0-9]', '', s).lower() + + return alphabet == alphabet[::-1] + + + From ecc6eccf9292429adf3ee7e29583ed3e4b67e385 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA Date: Wed, 26 Nov 2025 22:43:04 +0900 Subject: [PATCH 2/3] [:solved] #254 --- combination-sum/ppxyn1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 combination-sum/ppxyn1.py diff --git a/combination-sum/ppxyn1.py b/combination-sum/ppxyn1.py new file mode 100644 index 0000000000..3710bc44e9 --- /dev/null +++ b/combination-sum/ppxyn1.py @@ -0,0 +1,27 @@ +# idea: brute force +# Complexity: O(len(candidates)^(target / min(candidates))) + +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + candidates.sort() + result = [] + nums = [] + + def dfs(start: int, total: int): + if total > target: + return + if total == target: + result.append(nums.copy()) + return + for i in range(start, len(candidates)): + num = candidates[i] + if total + num > target: + break + nums.append(num) + dfs(i, total + num) + nums.pop() + dfs(0, 0) + return result + + + From 8220836f37218d7335ba45f41d7bec229f19b612 Mon Sep 17 00:00:00 2001 From: YOUNGJIN NA <120540450+ppxyn1@users.noreply.github.com> Date: Fri, 28 Nov 2025 22:29:13 +0900 Subject: [PATCH 3/3] [:solved] two problems --- decode-ways/ppxyn1.py | 19 +++++++++++++++++++ maximum-subarray/ppxyn1.py | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 decode-ways/ppxyn1.py create mode 100644 maximum-subarray/ppxyn1.py diff --git a/decode-ways/ppxyn1.py b/decode-ways/ppxyn1.py new file mode 100644 index 0000000000..52bdd2c58b --- /dev/null +++ b/decode-ways/ppxyn1.py @@ -0,0 +1,19 @@ +# idea : Tree +class Solution: + def numDecodings(self, s: str) -> int: + # recurisve : top-down + # DP : bottom-up can be another way to solve it, but it is not clear for me. + memo = {len(s):1} + def dfs(start): + if start in memo: + return memo[start] + if s[start] == '0': + memo[start] = 0 + elif start+1 < len(s) and int(s[start:start+2]) < 27: + memo[start] = dfs(start+1) + dfs(start+2) + else: + memo[start] = dfs(start+1) + return memo[start] + return dfs(0) + + diff --git a/maximum-subarray/ppxyn1.py b/maximum-subarray/ppxyn1.py new file mode 100644 index 0000000000..4948a74470 --- /dev/null +++ b/maximum-subarray/ppxyn1.py @@ -0,0 +1,21 @@ +# idea : DP +class Solution: + def maxSubArray(self, nums: List[int]) -> int: + # The solution must run in O(N^2) or better. + ''' + 1. Idea: Sorting + Two Pointers (x) — This problem does not allow changing the original order of the array. + 2. Subarrays (TLE) — O(N^3), too slow. + 3. DP (o) + ''' + max_total = nums[0] + total = nums[0] + # dp = [0]*len(nums) + # dp[0] = nums[0] + for i in range(1,len(nums)): + # dp[i] = max(nums[i], dp[i-1]+nums[i]) + total = max(nums[i], total+nums[i]) + max_total = max(total, max_total) + return max_total + + +