Java solution using bit manipulation
public class Solution {\n        public List<List<Integer>> subsetsWithDup(int[] num) {\n            Arrays.sort(num);\n            List<List<Integer>> lists = 
    public class Solution {\n        public List<List<Integer>> subsetsWithDup(int[] num) {\n            Arrays.sort(num);\n            List<List<Integer>> lists = new ArrayList<>();\n            int subsetNum = 1<<num.length;\n            for(int i=0;i<subsetNum;i++){\n                List<Integer> list = new ArrayList<>();\n                boolean illegal=false;\n                for(int j=0;j<num.length;j++){\n                    if((i>>j&1)==1){\n                        if(j>0&&num[j]==num[j-1]&&(i>>(j-1)&1)==0){\n                            illegal=true;\n                            break;\n                        }else{\n                            list.add(num[j]);\n                        }\n                    }\n                }\n                if(!illegal){\n                   lists.add(list); \n                }\n                \n            }\n            return lists;\n        }\n    }\n\nThe idea is using every bit to represent one element in the set. The total number is 2 to num.length. Then we need to avoid duplicates. After we sort the array, the same number will be adjacent to each other. \n\nFor example the set is {1,1,1}. We can get subset {} and {1} first. That's great.\nThen we need to pay attention. Suppose we have a subset x, which including the second 1 but not the first 1, x is a duplicate. \nThat's why I write the predicate:\nif(j>0&&num[j]==num[j-1]&&(i>>(j-1)&1)==0){\n                            illegal=true;\n                            break;\n}\n\nHope someone can explain it better. I will go to gym now.
[]