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 946129e commit 5d37cb5Copy full SHA for 5d37cb5
1 file changed
combination-sum/acious.kt
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ fun combinationSum(candidates: IntArray, target: Int): List<List<Int>> {
3
+ val result = mutableListOf<List<Int>>()
4
+ val current = mutableListOf<Int>()
5
+
6
+ fun dfs(start: Int, total: Int) {
7
+ if (total > target) return
8
9
+ if (total == target) {
10
+ result.add(ArrayList(current))
11
+ return
12
+ }
13
14
+ for (i in start until candidates.size) {
15
+ val num = candidates[i]
16
+ current.add(num)
17
+ dfs(i, total + num)
18
+ current.removeAt(current.size - 1)
19
20
21
22
+ dfs(0, 0)
23
+ return result
24
25
+}
0 commit comments