Python one-liner beats 99% using reduce

  • 0
    class Solution(object):
        def subsets(self, nums):
            return reduce(lambda t, n: [a + [n] for a in t] + t, nums, [[]])
        def subsets_in_other_words(self, nums):
            t = [[]]
            for n in nums:
                t = [a + [n] for a in t] + t
            return t

Log in to reply

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