king_crimson10

subsets

May 21st, 2022 (edited)
361
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def subsets(self, nums: List[int]) -> List[List[int]]:
  3.        
  4.         num_set = set(nums)
  5.         res_set = {(),tuple(nums)}
  6.        
  7.         def recurse(n_set):
  8.             if len(n_set)==1:
  9.                 res_set.add(tuple(n_set))
  10.            
  11.             for num in n_set:
  12.                 if tuple(n_set-{(num)}) not in res_set:
  13.                     recurse(n_set-{(num)})
  14.                 res_set.add(tuple(n_set-{(num)}))
  15.         recurse(num_set)
  16.         res = []
  17.         for n in res_set:
  18.             res.append(list(n))
  19.            
  20.         return res
RAW Paste Data Copied