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 557a5af commit 3e593f4Copy full SHA for 3e593f4
combination-sum/ohkingtaek.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3
+ """
4
+ - 시간복잡도: O(n^2)
5
+ - 공간복잡도: O(n)
6
+ DFS 사용
7
+ 1. 모든 조합을 찾기
8
+ 2. 조합을 찾을 때, 중복된 조합을 방지하기
9
10
+ result = []
11
+
12
+ def dfs(start, path, total):
13
+ if total == target:
14
+ result.append(path[:])
15
+ return
16
+ if total > target:
17
18
19
+ for i in range(start, len(candidates)):
20
+ path.append(candidates[i])
21
+ dfs(i, path, total + candidates[i])
22
+ path.pop()
23
24
+ dfs(0, [], 0)
25
+ return result
0 commit comments