LeetCode20. 有效的括号
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/combination-sum/description/
代码
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