Accepted java iterative solution
for explanation plz see comments in the code \n\n    public List> subsetsWithDup(int[] num) {\n        Arrays.sort(num);\n        List> ans = new ArrayList>();\
for explanation plz see comments in the code \n\n    public List<List<Integer>> subsetsWithDup(int[] num) {\n        Arrays.sort(num);\n        List<List<Integer>> ans = new ArrayList<List<Integer>>();\n        int len = num.length;\n        if (len == 0) return ans; \n        \n        ans.add(new ArrayList<Integer>()); // first, need to add the subset of num[0]\n        ans.add(new ArrayList<Integer>());\n        ans.get(1).add(num[0]);\n        \n        int nprev = 1; // this is the number of lists that the previous number was added in.\n                     // if the current number is same as the prev one, it'll be only added in the \n                    // lists that has the prev number.\n                    \n        for (int i = 1; i < len ; ++i){\n            int size = ans.size();\n            if (num[i]!=num[i-1])   // if different\n                nprev = size;        // this means add num[i] to all lists in ans;\n            for (int j = size-nprev; j < size; ++j){\n                List<Integer> l = new ArrayList<Integer>(ans.get(j));\n                l.add(num[i]);\n                ans.add(l);\n            }\n        }\n        return ans;\n    }
[]