题目:
题解:
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
if not nums:
return list()
results = list()
nums.sort()
visited = [False] * len(nums)
self.dfs(nums, results, list(), visited, 0)
return results
def dfs(self, nums, results, path, visited, start):
results.append(list(path))
for i in range(start, len(nums)):
if visited[i]:
continue
if i > 0 and nums[i] == nums[i - 1] and not visited[i - 1]:
continue
path.append(nums[i])
visited[i] = True
self.dfs(nums, results, path, visited, i + 1)
path.pop()
visited[i] = False
return