class Solution { public List<List<Integer>> subsetsWithDup(int[] nums) { Arrays.sort(nums); List<List<Integer>> res=new ArrayList<>(); boolean[] visit=new boolean[nums.length]; bs(res,new ArrayList<Integer>(),nums,0,visit); return res; } private void bs(List<List<Integer>> res,List<Integer> tmp,int[] nums,int start,boolean[] visit){ res.add(new ArrayList<>(tmp)); for(int i=start;i<nums.length;i++){ if(i!=0&&nums[i]==nums[i-1]&&!visit[i-1]){ continue; } tmp.add(nums[i]); visit[i]=true; bs(res,tmp,nums,i+1,visit); tmp.remove(tmp.size()-1); visit[i]=false; } } }