10 lines of Python code using lambda

  • 0
    class Solution(object):
        def combinationSum(self, c, t, k=0):
            if t == 0:
                return [[]]
            elif t < 0:
                return []
            res = []
            for i in range(k, len(c)):
                res.extend(map(lambda x: [c[i]] + x, self.combinationSum(c, t - c[i], i)))
            return res

Log in to reply

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