My AC Python code

  • 0

    It is also a reduce-and-conquer problem.

    class Solution(object):
        def subsets(self, nums):
            :type nums: List[int]
            :rtype: List[List[int]]
            def gen_subset(nums, begin, end):
                if end-begin == 0:  return [[]]
                tmp = gen_subset(nums, begin+1, end)  # exclude nums[0]
                sets =  tmp[:]
                for x in tmp:
                return sets
            return gen_subset(nums, 0, len(nums))

Log in to reply

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