Python Recursive Version

  • 0
    class Solution(object):
        def subsets(self, nums):
            result,each = [],[]
            count = len(nums)
            self.helper(nums, result, each, count)
            return result
        def helper(self, nums, result, each, count):
            if count == 0:return result.append(each)
            self.helper(nums[1:], result, each + [nums[0]], count - 1)
            self.helper(nums[1:], result, each, count - 1)

Log in to reply

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