Skip to content

Commit 8dfc886

Browse files
committed
combination-sum
1 parent 216fbcb commit 8dfc886

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

combination-sum/changhyumm.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3+
ans = []
4+
def combination(index, cur_comb, cur_sum):
5+
if cur_sum == target:
6+
ans.append(cur_comb[:])
7+
return
8+
if cur_sum > target or index >= len(candidates):
9+
return
10+
cur_comb.append(candidates[index])
11+
combination(index, cur_comb, cur_sum + candidates[index])
12+
# 합이 target이랑 같던지, 크던지, 길이를 넘던지하면 return으로 탈출
13+
# 그 외에 다른 경우의 수를 봐야하므로
14+
# 마지막꺼는 다시 빼고 어쨌든 index 넘겨서 다시 combination 확인해봐야함
15+
cur_comb.pop()
16+
combination(index + 1, cur_comb, cur_sum)
17+
return ans
18+
19+
return combination(0, [], 0)

number-of-1-bits/changhyumm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def hammingWeight(self, n: int) -> int:
88
n = n // 2
99
else:
1010
n = n / 2
11-
return count
11+
return count

0 commit comments

Comments
 (0)