Simple python solution beats 88.37%

  • 0
    class Solution(object):
        def combinationSum2(self, candidates, target):
            results = [set([()])] + [set([]) for i in xrange(target)];
            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.