Skip to content

Commit ae107c8

Browse files
Solve : Combination Sum
1 parent 6a2d333 commit ae107c8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

combination-sum/printjin-gmailcom.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def combinationSum(self, candidates, target):
3+
output, nums = [], []
4+
def dfs(start, total):
5+
if total > target:
6+
return
7+
if total == target:
8+
return output.append(nums[:])
9+
for i in range(start, len(candidates)):
10+
num = candidates[i]
11+
nums.append(num)
12+
dfs(i, total + num)
13+
nums.pop()
14+
dfs(0, 0)
15+
return output

0 commit comments

Comments
 (0)