@@ -0,0 +1,1515 @@
+/*%0A *Key point: dfs, much like Subsets question%0A *   the only difference is that skip duplicate elements before next iteration%0A *   which is to avoid duplicate subsets%0A *%0A *   I was going to use HashMap to eliminate duplicate subsets, but analysizing how%0A *   duplicate subsets are generated can conceive a easier solution%0A */%0A%0Apublic class Solution %7B%0A    public ArrayList%3CArrayList%3CInteger%3E%3E subsetsWithDup(int%5B%5D num) %7B%0A        if(num == null)%0A            return null;%0A        %0A        ArrayList%3CArrayList%3CInteger%3E%3E result = new ArrayList%3CArrayList%3CInteger%3E%3E();%0A        ArrayList%3CInteger%3E temp = new ArrayList%3CInteger%3E();%0A        %0A        result.add(temp);%0A        %0A        //sort array to meet non-descending order requirement%0A        Arrays.sort(num);%0A        %0A        dfsWorker(num, 0, result, temp);%0A        %0A        return result;%0A    %7D%0A    %0A    public void dfsWorker(int%5B%5D num, int position, ArrayList%3CArrayList%3CInteger%3E%3E result, ArrayList%3CInteger%3E temp)%7B%0A        for(int i = position;i%3Cnum.length;i++)%7B%0A            temp.add(num%5Bi%5D);%0A            %0A            //call dfsWorker() recursively%0A            dfsWorker(num, i+1, result, temp);%0A            %0A            result.add((ArrayList%3CInteger%3E) temp.clone());%0A            %0A            //remove current elements before next iteration%0A            temp.remove(Integer.valueOf(num%5Bi%5D));%0A            %0A            //skip duplicate elements to avoid duplicate subsets%0A            while(i %3C num.length - 1 && num%5Bi%5D == num%5Bi+1%5D)%0A                i++;%0A        %7D%0A    %7D%0A%7D

add solution for Subsets ii