Unique Java Solution using HashSet to avoid Duplicates
The Basic Idea is to use HashSet to remove the duplicates and procede as you solve the Subset problem, that is either choose a particular element or not choose.
The Basic Idea is to use HashSet to remove the duplicates and procede as you solve the Subset problem, that is either choose a particular element or not choose. \nAlso don\'t forget to sort the array beforehand so that there is no duplicate ordering of the numbers inside the final answer!\n\n```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        List<List<Integer>> ans = new ArrayList<List<Integer>>();\n        Arrays.sort(nums);\n        helper(nums,0,ans,new ArrayList<Integer>());\n        List<List<Integer>> newAns = new ArrayList<List<Integer>>();\n        HashSet<List<Integer>> set = new HashSet<>();\n        for(List<Integer> curr : ans){\n            set.add(curr);\n        }\n        for(List<Integer> curr : set){\n            newAns.add(curr);\n        }\n        return newAns;\n    }\n    public void helper(int[] nums, int i, List<List<Integer>> ans, ArrayList<Integer> curr){\n        if(i == nums.length){\n            ans.add(new ArrayList<Integer>(curr));\n            return;\n        }\n        curr.add(nums[i]);\n        helper(nums,i+1,ans,curr);\n        curr.remove(curr.size()-1);\n        helper(nums,i+1,ans,curr);\n    }\n}\n```\nPlease upvote if found helpful!!
['Java']