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