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 9fdd210 commit 3645265Copy full SHA for 3645265
Combination Sum/Combination_Sum.py
@@ -0,0 +1,25 @@
1
+# 76ms 81.65%
2
+class Solution:
3
+ def combinationSum(self, candidates, target):
4
+ """
5
+ :type candidates: List[int]
6
+ :type target: int
7
+ :rtype: List[List[int]]
8
9
+ # 把reslist写在前面会大幅度提高处理速度
10
+ res_list, len_nums = [], len(candidates)
11
+ candidates.sort()
12
+
13
+ def mysum(target, temp_list, start_index = 0):
14
+ for index in range(start_index, len_nums):
15
+ temp = target - candidates[index]
16
+ if temp is 0:
17
+ res_list.append(temp_list + [candidates[index]])
18
+ elif temp < 0:
19
+ break
20
+ else:
21
+ # 这里为了去重,增加了一个start_index
22
+ mysum(temp, temp_list + [candidates[index]], index)
23
24
+ mysum(target, [])
25
+ return res_list
0 commit comments