-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ39.py
More file actions
23 lines (21 loc) · 874 Bytes
/
Q39.py
File metadata and controls
23 lines (21 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import List
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
solution = []
def backTrace(currSum,currList,mainList):
for i in range(len(mainList)):
if currSum+mainList[i] == target:
tempList = currList+[mainList[i]]
tempList.sort()
if tempList not in solution:
solution.append(tempList)
continue
elif currSum+mainList[i] > target:
continue
else:
backTrace(currSum+mainList[i],currList+[mainList[i]],mainList)
return
backTrace(0,[],candidates)
return solution
if __name__ == '__main__':
print(Solution().combinationSum([8,7,4,3],11))