my clear java solution


  • 0
    F
    List<List<Integer>> re=new ArrayList<List<Integer>>();
    	List<Integer> temp=new ArrayList<>();
    	void helper(int index,int[] nums){
    		if(index==nums.length){
    			re.add(new ArrayList<>(temp));
    			return;
    		}
    		temp.add(nums[index]);
    		helper(index+1, nums);
    		temp.remove(temp.size()-1);
    		helper(index+1, nums);
    	}
    	public List<List<Integer>> subsets(int[] nums) {
            helper(0, nums);
            return re;
        }
    

Log in to reply
 

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