leetcode 40. 组合总和 II

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

上一篇:利用MLP进行分类


下一篇:Nginx+Keepalived实现简单的服务高可用