-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathset.py
More file actions
31 lines (23 loc) · 1 KB
/
set.py
File metadata and controls
31 lines (23 loc) · 1 KB
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
class Solution(object):
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
# Using itertools combinations - Short and easy logic - 100pass
import itertools
result = [list(nums)]
# When the full array length is taken, we dont want combination where len== len(nums) hence reduced the iteration by 1
for i in range(len(nums)):
for comb in itertools.combinations(nums,i): # use permutation when order is important as in (2,1) != (1,2)
# Sorted the nums in order to help eradiation duplicates
result.append(sorted(comb))
print result
#return sorted(list(set(result)))
#return list(set(sorted(result)))
# Eradicating duplicates of list of list
answer = []
for item in result:
if item not in answer:
answer.append(item)
return answer