Skip to content

Instantly share code, notes, and snippets.

@braddotcoffee
Created November 21, 2023 22:02
Show Gist options
  • Save braddotcoffee/ce278890777b12a962dc8f6887592de0 to your computer and use it in GitHub Desktop.
Save braddotcoffee/ce278890777b12a962dc8f6887592de0 to your computer and use it in GitHub Desktop.
78. Subsets
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