-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path90.py
35 lines (32 loc) · 1.35 KB
/
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
34
35
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
nums.sort()
combinations = []
self.dfs(nums, 0, [], combinations)
return combinations
def dfs(self, nums, index, combination, combinations):
combinations.append(list(combination))
for i in range(index, len(nums)):
if i != index and nums[i] ==nums[i-1]:
continue
combination.append(nums[i])
self.dfs(nums, i + 1, combination, combinations)
combination.pop()
__________________________________________________________________________________________________
sample 13100 kb submission
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
nums.sort()
self.res = []
self.helper([], 0, nums)
return self.res
def helper(self, path, depth, nums):
if depth >= len(nums):
if path not in self.res:
self.res.append(path)
return
self.helper(path, depth+1, nums)
self.helper(path+[nums[depth]], depth+1, nums)
__________________________________________________________________________________________________