-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0090_Subsets_II.py
More file actions
23 lines (22 loc) · 814 Bytes
/
Copy path0090_Subsets_II.py
File metadata and controls
23 lines (22 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
def backtrack(idx, cur_ans):
ans.append(cur_ans)
for j in range(idx, len(nums)):
if j > idx and nums[j] == nums[j - 1]:
continue
backtrack(j + 1, cur_ans + [nums[j]])
ans = []
nums.sort()
backtrack(0, [])
return ans
'''generate all n! and use hashset to record unique ones'''
# def backtrack(idx, cur_ans):
# if idx == len(nums):
# ans.add(tuple(sorted(cur_ans)))
# return
# backtrack(idx + 1, cur_ans + [nums[idx]])
# backtrack(idx + 1, cur_ans)
# ans = set()
# backtrack(0, [])
# return list(ans)