Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions combination-sum/sangbeenmoon.py
Original file line number Diff line number Diff line change
@@ -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()






9 changes: 9 additions & 0 deletions number-of-1-bits/sangbeenmoon.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions valid-palindrome/sangbeenmoon.py
Original file line number Diff line number Diff line change
@@ -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
Loading