Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #unique subsets
- class Solution:
- def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
- ans=[]
- st=[]
- n=len(nums)
- nums.sort()
- def dfs(i):
- if i>=n:
- print(st,ans)
- ans.append(st[:])
- return
- st.append(nums[i])
- dfs(i+1)
- st.pop()
- while i+1<n and nums[i]==nums[i+1]:
- i=i+1
- dfs(i+1)
- return
- dfs(0)
- return ans
- '''
- #Repeated subsets
- Just above code remove that while loop
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement