classSolution:defsubsetsWithDup(self,nums: List[int]) -> List[List[int]]: nums.sort() res = []defdfs(pos,res,path):for i inrange(pos, len(nums)):if i == pos or nums[i]!= nums[i -1]: path.append(nums[i])dfs(i +1, res, path) path.pop() res.append([i for i in path])dfs(0, res, [])return res
classSolution {privatevoidhelper(int[] nums,int start,List<Integer> path,List<List<Integer>> res) {res.add(newArrayList<>(path));for (int i = start; i <nums.length; i++) {if (i > start && nums[i] == nums[i -1]) {continue; }path.add(nums[i]);helper(nums, i +1, path, res);path.remove(path.size() -1); } }publicList<List<Integer>> subsetsWithDup(int[] nums) {Arrays.sort(nums);List<List<Integer>> res =newArrayList<>();helper(nums,0,newArrayList<>(), res);return res; }}