class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
res = []
tmp = []
def backtrace(starIndex: int) -> None:
if(sum(tmp) == target):
res.append(tmp.copy())
return
if(sum(tmp) <= target):
for i in range(starIndex, len(candidates), 1):
tmp.append(candidates[i])
backtrace(i)
tmp.pop()
backtrace(0)
return res
#39. 组合总和
最新推荐文章于 2023-12-04 16:25:04 发布