90. Subsets II
public class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> res=new ArrayList<List<Integer>>(); Arrays.sort(nums); subsetsWithDup(0, new ArrayList<Integer>(), res, nums); return res; } private void subsetsWithDup(int idx, List<Integer> list, List<List<Integer>> res, int[] nums){ res.add(new ArrayList<Integer>(list)); for(int i=idx;i<nums.length;i++) { if(i!=idx&&nums[i]==nums[i-1]) continue; list.add(nums[i]); subsetsWithDup(i+1,list,res,nums); list.remove(list.size()-1); } } }