-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path39.py
30 lines (24 loc) · 821 Bytes
/
39.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import List
import copy
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
res = []
temp = []
temp_target = 0
def combinationSum_inner(start):
nonlocal temp_target
if temp_target > target:
return
if temp_target == target:
res.append(copy.deepcopy(temp))
for index,num in enumerate(candidates[start:]):
temp.append(num)
temp_target += num
combinationSum_inner(index+start)
temp.pop()
temp_target -= num
combinationSum_inner(0)
return res
if __name__ == '__main__':
soul = Solution()
print(soul.combinationSum([2], target = 1))