leetcod hot 19----100

leetcod  hot  19----100

class Solution:
    def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
        if(not candidates):
            return []
        n=len(candidates)
        res=[]
        candidates.sort()
        def helper(i,tmp,target):
            if(target==0):
                res.append(tmp)
                return
            if(i==n or target<candidates[i]):
                return
            helper(i,tmp+[candidates[i]],target-candidates[i])
            helper(i+1,tmp,target)
        helper(0,[],target)
        return res

leetcod  hot  19----100

leetcod  hot  19----100leetcod  hot  19----100 weixin_45568353 发布了96 篇原创文章 · 获赞 1 · 访问量 1806 私信 关注
上一篇:Leetcode-39 组合总和


下一篇:PHP-组合总和