Java concise - 4 solutions, 0 ms, 100% beats
1. Regular recursion\n\n// Each recursion level focuses on all the following elements.\n// We scan through all the following elements and decide whether to choo
**1. Regular recursion**\n```\n// Each recursion level focuses on all the following elements.\n// We scan through all the following elements and decide whether to choose or not choose that element. (Every level split into N branches.)\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        List<List<Integer>> result = new ArrayList<>();\n        Arrays.sort(nums);\n        subsets(nums, 0, new LinkedList<>(), result);\n        return result;\n    }\n    \n    private void subsets(int[] nums, int start, LinkedList<Integer> set, List<List<Integer>> sets) {\n        sets.add(new ArrayList(set));\n        for(int i=start; i<nums.length; i++) {\n            // If candidate[i] equals candidate[i-1], then solutions for i is subset of solution of i-1\n            // Refer: https://leetcode.com/problems/combination-sum-ii/discuss/16861/Java-solution-using-dfs-easy-understand/977097\n            if (i==start || (i>start && nums[i] != nums[i-1])) {\n                set.addLast(nums[i]);\n                // \'i+1\' (not \'i\') because can\'t reuse same element to help avoid duplicate subsets\n                subsets(nums, i+1, set, sets);\n                set.removeLast();\n            }\n        }\n    }\n}\n```\n**2. Optimized recursion**\n```\n// Each recursion level focuses on one element, we need to decide choose or not choose this element. (Every level split into 2 branches.)\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n\t    // Sort to assist check for adjacent elements to avoid duplicates\n        Arrays.sort(nums);\n        List<List<Integer>> res = new ArrayList<>();\n        subsetsWithDup(res, new ArrayList<>(), nums, 0, false);\n        return res;\n    }\n\n    public void subsetsWithDup(List<List<Integer>> res, List<Integer> ls, int[] nums, int pos, boolean choosePre) {\n\t    // Update result with new set when all elements evaluated\n        if(pos == nums.length) {\n            res.add(new ArrayList<>(ls));\n            return;\n        }\n        subsetsWithDup(res, ls, nums, pos+1, false);\n\t\t// If previous is same and not chosen, then we can end up in duplicate set, hence skip\n        if(pos>=1 && nums[pos]==nums[pos-1] && !choosePre) return;\n        ls.add(nums[pos]);\n        subsetsWithDup(res, ls, nums, pos+1, true);\n        ls.remove(ls.size()-1);\n    }\n}\n```\n3. **Using Bit mask for set generation. Using sort (with hashset) for deduplication**\n```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        // Get possible sets\n        int possibleSets = 1<<nums.length;\n        // Use hashset + sort to avoid duplicates\n        Set<List<Integer>> sets = new HashSet<>();\n        Arrays.sort(nums);\n        // Pick a set to fill\n        for (int i=0; i<possibleSets; i++) {\n            List<Integer> set = new ArrayList<>();\n            // Fill with nums[j] if the bit corresponding to the jth index in i is set\n            for (int j=0; j<nums.length; j++) {\n                if((1 & (i>>j)) == 1) {\n                    set.add(nums[j]);\n                }\n            }\n            sets.add(set);\n        }\n        return new ArrayList<>(sets);\n    }\n}\n```\n4. **Using Bit mask for set generation. Using sort (without hashset) for deduplication**\n```\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        // Get possible sets\n        int possibleSets = 1<<nums.length;\n        // Use sort + repeated element check to avoid duplicates\n        List<List<Integer>> sets = new ArrayList<>();\n        Arrays.sort(nums);\n        // Pick a set to fill\n        for (int i=0; i<possibleSets; i++) {\n            List<Integer> set = new ArrayList<>();\n            boolean duplicateSet = false;\n            // Fill with nums[j] if the bit corresponding to the jth index in i is set\n            for (int j=0; j<nums.length; j++) {\n                // If jth element needs to be picked\n                if ((1 & (i>>j)) == 1) {\n                    // After we sort the array, the same number will be adjacent to each other.\n                    // For example the set is {1,1,1}. We can get subset {} and {1} first. That\'s great.\n                    // Now, suppose we have a subset x, which including the second 1 but not the first 1, x is a duplicate.\n                    if (j==0 || (j>0 && (nums[j] != nums[j-1] || (1 & (i>>(j-1))) == 1))) {\n                        set.add(nums[j]);\n                    } else {\n                        duplicateSet = true;\n                        break;\n                    }\n                }\n            }\n            if (!duplicateSet) {\n                sets.add(set);\n            }\n        }\n        return sets;\n    }\n}\n```
['Bit Manipulation', 'Combinatorics']