From 7574a46baded5ab529299c6232650df896a104bd Mon Sep 17 00:00:00 2001 From: sangbeenmoon Date: Thu, 19 Mar 2026 21:23:21 +0900 Subject: [PATCH 1/4] solved combination-sums. --- combination-sum/sangbeenmoon.py | 26 ++++++++++++++++++++++++++ valid-palindrome/sangbeenmoon.py | 21 +++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 combination-sum/sangbeenmoon.py create mode 100644 valid-palindrome/sangbeenmoon.py diff --git a/combination-sum/sangbeenmoon.py b/combination-sum/sangbeenmoon.py new file mode 100644 index 0000000000..998009875f --- /dev/null +++ b/combination-sum/sangbeenmoon.py @@ -0,0 +1,26 @@ +# TC : O(2^target) 재귀 트리의 분기 수 +# SC : O(target/min(candidates)) 재귀 스택 깊이 + +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + self.answer = [] + for i in range(len(candidates)): + self.go(i, candidates, [candidates[i]], candidates[i], target) + + return self.answer + + def go(self, i:int, candidates: List[int], nums: List[int], sum_: int, target: int): + if sum_ == target: + self.answer.append(nums.copy()) + + for j in range(i, len(candidates)): + if candidates[j] + sum_ <= target: + nums.append(candidates[j]) + self.go(j, candidates, nums, sum_ + candidates[j], target) + nums.pop() + + + + + + diff --git a/valid-palindrome/sangbeenmoon.py b/valid-palindrome/sangbeenmoon.py new file mode 100644 index 0000000000..90967855cb --- /dev/null +++ b/valid-palindrome/sangbeenmoon.py @@ -0,0 +1,21 @@ +# TC : O(n) +# SC : O(n) + +class Solution: + def isPalindrome(self, s: str) -> bool: + refined_s = [] + + for ch in s: + if 'a' <= ch and ch <= 'z' or ('0' <= ch and ch <= '9'): + refined_s.append(ch) + continue + + if 'A' <= ch and ch <= 'Z': + refined_s.append(ch.lower()) + + for i in range(len(refined_s)): + j = len(refined_s) - i - 1 + if refined_s[i] != refined_s[j]: + return False + + return True From 083991d9814902b2f9b511e704f05a84281b1681 Mon Sep 17 00:00:00 2001 From: sangbeenmoon Date: Thu, 19 Mar 2026 21:38:28 +0900 Subject: [PATCH 2/4] solved number-of-1-bits. --- number-of-1-bits/sangbeenmoon.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 number-of-1-bits/sangbeenmoon.py diff --git a/number-of-1-bits/sangbeenmoon.py b/number-of-1-bits/sangbeenmoon.py new file mode 100644 index 0000000000..17f0c03eea --- /dev/null +++ b/number-of-1-bits/sangbeenmoon.py @@ -0,0 +1,9 @@ +class Solution: + def hammingWeight(self, n: int) -> int: + cnt = 0 + while n > 0: + if n % 2 == 1: + cnt = cnt + 1 + n = n // 2 + print(n) + return cnt \ No newline at end of file From 120f01ee1e456498d322ee01cfc360531b466014 Mon Sep 17 00:00:00 2001 From: sangbeenmoon Date: Thu, 19 Mar 2026 21:38:45 +0900 Subject: [PATCH 3/4] solved number-of-1-bits. --- number-of-1-bits/sangbeenmoon.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/number-of-1-bits/sangbeenmoon.py b/number-of-1-bits/sangbeenmoon.py index 17f0c03eea..056cc5c06b 100644 --- a/number-of-1-bits/sangbeenmoon.py +++ b/number-of-1-bits/sangbeenmoon.py @@ -6,4 +6,5 @@ def hammingWeight(self, n: int) -> int: cnt = cnt + 1 n = n // 2 print(n) - return cnt \ No newline at end of file + return cnt + \ No newline at end of file From 9b7fd8584af7adc780600c04e2079ec37ff5cd04 Mon Sep 17 00:00:00 2001 From: sangbeenmoon Date: Thu, 19 Mar 2026 21:39:20 +0900 Subject: [PATCH 4/4] solved number-of-1-bits. --- number-of-1-bits/sangbeenmoon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/number-of-1-bits/sangbeenmoon.py b/number-of-1-bits/sangbeenmoon.py index 056cc5c06b..144e437598 100644 --- a/number-of-1-bits/sangbeenmoon.py +++ b/number-of-1-bits/sangbeenmoon.py @@ -7,4 +7,3 @@ def hammingWeight(self, n: int) -> int: n = n // 2 print(n) return cnt - \ No newline at end of file