using hashset easy code
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        // First, sort the array to handle duplicates easily\n        Arrays.sort(nums);\n\n        // Using a set to avoid duplicates\n        Set<List<Integer>> resultSet = new HashSet<>();\n        resultSet.add(new ArrayList<>());\n\n        for (int num : nums) {\n            Set<List<Integer>> newSubsets = new HashSet<>();\n            for (List<Integer> subset : resultSet) {\n                List<Integer> newSub = new ArrayList<>(subset);\n                newSub.add(num);\n                newSubsets.add(newSub);\n            }\n            resultSet.addAll(newSubsets);\n        }\n\n        // Convert the set back to a list\n        return new ArrayList<>(resultSet);\n    }\n}\n\n```
['Java']