Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # First Implementation
- class Solution:
- def subsets(self, nums: List[int]) -> List[List[int]]:
- def generate_subsets(start):
- if start >= len(nums):
- return [[]]
- subsets_without_num = generate_subsets(start + 1)
- subsets_with_num = [[nums[start]] + subset for subset in subsets_without_num]
- return subsets_without_num + subsets_with_num
- return generate_subsets(0)
- # Second Implementation
- class Solution:
- def subsets(self, nums: List[int]) -> List[List[int]]:
- if (len(nums)) == 0:
- return [[]]
- start = 0
- subsets_without_num = self.subsets(nums[:start] + nums[start+1:])
- subsets_with_num = [[nums[start]] + subset for subset in subsets_without_num]
- return subsets_without_num + subsets_with_num
Advertisement
Add Comment
Please, Sign In to add comment