Skip to content

Commit 05be2d5

Browse files
Add files via upload
1 parent dcf7e4a commit 05be2d5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 52ms 95.29%
2+
class Solution:
3+
def combinationSum2(self, candidates, target):
4+
"""
5+
:type candidates: List[int]
6+
:type target: int
7+
:rtype: List[List[int]]
8+
"""
9+
res_list = []
10+
candidates.sort()
11+
12+
def mysum(candidates, target, temp_list):
13+
for index in range(len(candidates)):
14+
if index > 0 and candidates[index] == candidates[index - 1]:
15+
continue
16+
temp = target - candidates[index]
17+
if temp is 0:
18+
res_list.append(temp_list + [candidates[index]])
19+
elif temp < 0:
20+
break
21+
else:
22+
mysum(candidates[index + 1:], temp, temp_list + [candidates[index]])
23+
24+
mysum(candidates, target, [])
25+
return res_list

0 commit comments

Comments
 (0)