forked from Garvit244/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path90.py
33 lines (29 loc) · 733 Bytes
/
90.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'''
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: [1,2,2]
Output:
[
[2],
[1],
[1,2,2],
[2,2],
[1,2],
[]
]
'''
class Solution(object):
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
result = [[]]
for num in nums:
for index in range(len(result)):
new_list = result[index] + [num]
new_list.sort()
result.append(new_list)
unique = set(tuple(val) for val in result)
return list(list(val) for val in unique)