题目:
题解:
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 resultsdef dfs(self, nums, results, path, visited, start):results.append(list(path))for i in range(start, len(nums)):if visited[i]:continueif i > 0 and nums[i] == nums[i - 1] and not visited[i - 1]:continuepath.append(nums[i])visited[i] = Trueself.dfs(nums, results, path, visited, i + 1)path.pop()visited[i] = Falsereturn