Created
November 21, 2023 22:02
-
-
Save braddotcoffee/ce278890777b12a962dc8f6887592de0 to your computer and use it in GitHub Desktop.
78. Subsets
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 depth_first_search(self, nums: List[int], curr_state: List[int], curr_idx: int): | |
if curr_idx == len(nums): | |
self.final_result.append(curr_state.copy()) | |
return | |
num = nums[curr_idx] | |
curr_state.append(num) | |
self.depth_first_search(nums, curr_state, curr_idx + 1) | |
curr_state.pop() | |
self.depth_first_search(nums, curr_state, curr_idx + 1) | |
def subsets(self, nums: List[int]) -> List[List[int]]: | |
self.final_result = list() | |
self.depth_first_search(nums, list(), 0) | |
return self.final_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment