Java solution


  • 0
    J
        List<List<Integer>> ans = new ArrayList<List<Integer>>();
        public List<List<Integer>> subsetsWithDup(int[] nums){
        	int start = 0, end = nums.length;
        	Arrays.sort(nums);
        	List<Integer> sub = new ArrayList<Integer>();
        	helper(sub,0,end-1,nums);
        	return ans;		
        }
        
        public void helper(List<Integer> sub, int start, int end, int[] nums){
        	if(!ans.contains(sub)) ans.add(new ArrayList<Integer>(sub));
        	while(start<=end){
        		sub.add(nums[start]);
        		helper(sub,start+1,end,nums);
        		sub.remove(sub.size()-1);
        		start++;	
        	}
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.