Simple python solution beats 88.37%


  • 0
    L
    class Solution(object):
        def combinationSum2(self, candidates, target):
            results = [set([()])] + [set([]) for i in xrange(target)];
            candidates.sort();
            for candidate in candidates:
                for temp_target in xrange(target, candidate - 1, -1):
                    for combination in results[temp_target - candidate]:
                        results[temp_target].add(combination + (candidate,));
            return [list(result) for result in results[target]]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.