We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dcf7e4a commit 05be2d5Copy full SHA for 05be2d5
Combination Sum II/Combination_Sum_II.py
@@ -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