Easy Thought, related programs


  • 0
    P
    public class Solution {
        public List<List<Integer>> subsetsWithDup(int[] nums) {
            List<Integer> item = new ArrayList<Integer>();
    		List<List<Integer>> result = new ArrayList<List<Integer>>();
    		Arrays.sort(nums);
    		getSubSetNoDup(result, item, nums, 0);
    		return result;
        }
    	
    	public void getSubSetNoDup(List<List<Integer>> result, List<Integer> item, int[] nums, int start){
    		result.add(new ArrayList<Integer> (item));
    		for(int i = start; i < nums.length; i++){
    			if(i > start && nums[i] == nums[i - 1])
    				continue; 
    			item.add(nums[i]);
    			getSubSetNoDup(result, item, nums, i + 1);
    			item.remove(item.size()-1);
    		}
    	}
    }
    

Log in to reply
 

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