We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c20a0af commit ffaa0f7Copy full SHA for ffaa0f7
combination-sum/yyyyyyyyyKim.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3
+
4
+ answer = []
5
6
+ # 재귀
7
+ def backtrack(start, path, total):
8
+ # total이 target과 같아지면 path복사해서 answer에 추가하고 종료
9
+ if total == target:
10
+ answer.append(path[:])
11
+ return
12
13
+ # total이 target값 넘어가면 종료
14
+ if total > target:
15
16
17
+ for i in range(start, len(candidates)):
18
+ path.append(candidates[i]) # 일단 path에 추가하고
19
+ backtrack(i, path, total + candidates[i]) # 검증하기
20
+ path.pop() # 마지막 값 꺼내고 다음으로
21
22
+ # backtrack 함수호출
23
+ backtrack(0, [], 0)
24
25
+ return answer
0 commit comments