题目链接
https://leetcode.cn/problems/combination-sum/description/文章来源地址https://www.toymoban.com/news/detail-704472.html
代码
class Solution:
def backtracking(self, candidates, stratindex, path, target, result, total):
if total > target:
return
if total == target:
result.append(path[:])
for i in range(stratindex, len(candidates)):
total += candidates[i]
path.append(candidates[i])
self.backtracking(candidates, i, path, target, result, total)
total -= candidates[i]
path.pop()
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
result = []
self.backtracking(candidates, 0, [], target, result, 0)
return result
文章来源:https://www.toymoban.com/news/detail-704472.html
到了这里,关于LeetCode(力扣)39. 组合总和Python的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!