Skip to content

Commit e021bb8

Browse files
committed
q39
1 parent c7a7a32 commit e021bb8

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
git submodule update --recursive --remote
4848
else
4949
echo "Submodule not found. Adding..."
50-
git submodule add https://github.com/Zanger67/Leetcode-Progress-Tracker.git '.readme_updater'
50+
git submodule add https://github.com/Zanger67/WikiLeet.git '.readme_updater'
5151
git submodule update --init --recursive
5252
fi
5353

my-submissions/m39.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution:
2+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3+
4+
def combos(outputs: List[List[int]],
5+
current: List[int] = [],
6+
currentSum: int = 0,
7+
candidates: List[int] = candidates) -> None :
8+
if currentSum > target :
9+
return
10+
if currentSum == target :
11+
outputs.append(current.copy())
12+
return
13+
if not candidates :
14+
return
15+
16+
hold = candidates.pop()
17+
combos(outputs, current, currentSum, candidates)
18+
currentSum += hold
19+
cnt = 0
20+
21+
while currentSum <= target :
22+
current.append(hold)
23+
cnt += 1
24+
combos(outputs, current, currentSum, candidates)
25+
currentSum += hold
26+
27+
for _ in range(cnt) :
28+
current.pop()
29+
candidates.append(hold)
30+
31+
candidates.sort()
32+
output = []
33+
combos(output)
34+
35+
return output

0 commit comments

Comments
 (0)