JAVA Easy to Understand Same logic of Subsets 1
\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        HashSet<List<Integer>> res = new HashSet<>(); // No need to add duplica
```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        HashSet<List<Integer>> res = new HashSet<>(); // No need to add duplicate subsets so hashset is used\n        backtrack(nums,res,new ArrayList<>(),0); \n        List<List<Integer>> ans = res.stream().map(i->i).collect(Collectors.toList()); // convert hashset to list\n        return ans;\n    }\n    public void backtrack(int[] nums,HashSet<List<Integer>> res,List<Integer> list,int idx){\n        if(idx == nums.length){\n            List<Integer> l = new ArrayList<>(list); // new list so the orignal list does no get changed\n            Collections.sort(l); // sorting the subsets \n            res.add(l);\n            return;\n        }\n        list.add(nums[idx]);  // number gets picked\n        backtrack(nums,res,list,idx+1);\n        list.remove(list.size()-1); // number does not get picked\n        backtrack(nums,res,list,idx+1);\n    }\n}\n```
[]