We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8ddc29 commit 0b7823aCopy full SHA for 0b7823a
18.py
@@ -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
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