import copy
class Solution(object):
def combinationSum2(self, candidates, target):
if candidates is []:
return []
results = []
result = []
candidates.sort()
def bp(candidates, target, loc, L, result):
if sum(candidates[loc+1:])+sum(result) < target:
return
if sum(result) == target:
if result not in results:
results.append(copy.copy(result))
return
if loc >= L - 1:
return
for i in range(loc, L-1):
if sum(result) < target:
result.append(candidates[i+1])
bp(candidates, target, i+1, L, result)
result.pop(-1)
bp(candidates, target, -1, len(candidates), result)
return results
相关文章
- 12-24【一天一道LeetCode】#40. Combination Sum II
- 12-24【LeetCode】216. 组合总和 III(回溯)
- 12-24LeetCode113. 路径总和 II
- 12-24Leetcode 377:组合总和IV
- 12-24LeetCode 216 组合总和
- 12-24Leetcode 216. 组合总和 III dfs
- 12-24【leetcode】377. 组合总和 Ⅳ(combination-sum-iv)(DP)[中等]
- 12-24LeetCode39.组合总和
- 12-24leetcode 49. 字母异位词分组 50. 组合总和 II
- 12-24Leetcode113. 路径总和 II