Given a set of integer arrays nums without repeated elements, return all possible subsets (power sets) of the array.
Note: The solution set cannot contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1 ,2],
[]
]
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList();
Deque<Integer> que = new LinkedList();
back(0,nums,que,res);
return res;
}
public void back(int start,int[] nums,Deque<Integer> que,List<List<Integer>> res){
res.add(new ArrayList(que));
for(int i=start;i<nums.length;i++){
que.addLast(nums[i]);
back(i+1,nums,que,res);
que.removeLast();
}
}
}