Skip to content

Commit 53a3fd3

Browse files
committed
combination-sum solution
1 parent 002a743 commit 53a3fd3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

combination-sum/yayyz.py

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

0 commit comments

Comments
 (0)