标签:res class def note dup NPU ati nbsp for
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
Time: O(2^n)
Space: O(N)
class Solution: def subsets(self, nums: ‘List[int]‘) -> ‘List[List[int]]‘: res = [] if nums is None or len(nums) == 0: return res self.helper(nums, 0, [], res) return res def helper(self, nums, index, combination, combinations): combinations.append(list(combination)) for i ian range(index, len(nums)): combination.append(nums[i]) self.helper(nums, i + 1, combination, combinations) combination.pop()
标签:res class def note dup NPU ati nbsp for
原文地址:https://www.cnblogs.com/xuanlu/p/11566071.html