输入:nums = [1,2,3] 输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
class Solution {
List<List<Integer>> res=new ArrayList<>();
List<Integer> temp=new ArrayList<Integer>();
public List<List<Integer>> subsets(int[] nums) {
helper(nums,0);
return res;
}
public void helper(int [] nums,int start){
res.add(new ArrayList<>(temp)); //一定要新开一个集合 跟list内容一样
for(int i=start;i<nums.length;i++){
temp.add(nums[i]);
helper(nums,i+1);
temp.remove(temp.size()-1);
}
}
}