Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created June 9, 2024 10:47
Show Gist options
  • Save codecakes/508d23cc639e506e46b8578179426f5c to your computer and use it in GitHub Desktop.
Save codecakes/508d23cc639e506e46b8578179426f5c to your computer and use it in GitHub Desktop.
array nums of unique integers, return all possible combination of subsets of nums.
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
def do_generate(result, slate, subset):
result += [slate]
for idx, num in enumerate(subset):
new_subset = subset[idx+1:]
do_generate(result, slate + [num], new_subset)
return result
return do_generate([], [], nums)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment