Skip to content

Commit 06dd433

Browse files
author
wuduhren
committed
subsets-ii
1 parent ec99f02 commit 06dd433

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

problems/python3/subsets-ii.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
3+
def helper(i):
4+
if i==len(nums):
5+
ans.append(subset.copy())
6+
return
7+
8+
subset.append(nums[i])
9+
helper(i+1)
10+
subset.pop()
11+
12+
while i+1<len(nums) and nums[i]==nums[i+1]: i += 1
13+
helper(i+1)
14+
15+
nums.sort()
16+
ans = []
17+
subset = []
18+
helper(0)
19+
return ans

0 commit comments

Comments
 (0)