Created
June 9, 2024 10:47
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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