78. Subsets

#### QUESTION:

Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

For example, If nums = `[1,2,3]`, a solution is:

``````[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
``````

#### EXPLANATION:

length=0 length=1 length=2的时候，这样的所有组合，然后取出重复的就可以。

#### SOLUTION:

``````class Solution {
List<List<Integer>> subsetsResult = new ArrayList<>();
public List<List<Integer>> subsets(int[] nums) {
ArrayList<Integer> tmp = new ArrayList<>();
ArrayList<Integer> integers = new ArrayList<>();
for(int i = 0;i<integers.size();i++) subsetsHelper(integers,tmp,i);
return subsetsResult;
}
public void subsetsHelper(List<Integer> list,List<Integer> tmp,int length){
if(tmp.size()==length){
}else {
for(int i =0;i<list.size();i++){
if(tmp.size()>=1&&list.get(i)<tmp.get(tmp.size()-1))continue;
Integer removed = list.remove(i);
subsetsHelper(list,tmp,length);
tmp.remove(tmp.size()-1);
}
}
}
}

class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
List<Integer> subset = new ArrayList<>();
if (nums == null || nums.length == 0) {
return result;
}

dfsHelper(nums, 0, subset, result);
return result;
}

private void dfsHelper(int[] nums, int start, List<Integer> subset, List<List<Integer>> result) {