Skip to content

Commit 0b7823a

Browse files
committed
9.26
1 parent d8ddc29 commit 0b7823a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

18.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution:
2+
"""
3+
@param nums: A set of numbers.
4+
@return: A list of lists. All valid subsets.
5+
"""
6+
def subsetsWithDup(self, nums):
7+
# write your code here
8+
res = []
9+
nums.sort()
10+
res.append(nums)
11+
index = 0
12+
while index < len(res):
13+
if len(res[index]) == 1:
14+
index += 1
15+
continue
16+
arr = res[index]
17+
for num in arr:
18+
tmp = []
19+
for i in arr:
20+
#if i != num:
21+
tmp.append(i)
22+
if len(tmp) <= 2:
23+
tmp.sort()
24+
if tmp not in res:
25+
res.append(tmp)
26+
index += 1
27+
if [] not in res:
28+
res.append([])
29+
res.sort()
30+
return res
31+
32+
33+
A = [1, 2, 2]
34+
print(Solution.subsetsWithDup(A, A))

0 commit comments

Comments
 (0)