45ms Python solution


  • 0
    Y
    def subsets(xs, res=None, k=0):
        if res is None:
            res = []
        if k == len(xs):
            res.append([])
        else:
            # get all subsets excluding xs[k]
            subsets(xs, res, k + 1)
            incl = [subset + [xs[k]] for subset in res]
            res += incl
        return res
    

Log in to reply
 

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