Medium
应该可以秒的,但是i+1那里一开始写成了index+1
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
List<Integer> list = new ArrayList<>();
dfsHelper(res, list, nums, 0);
return res;
}
private void dfsHelper(List<List<Integer>> res, List<Integer> list, int[] nums, int index){
res.add(new ArrayList<Integer>(list));
for(int i = index; i < nums.length; i++){
if (list.contains(nums[i])){
continue;
}
list.add(nums[i]);
dfsHelper(res, list, nums, i + 1);
list.remove(list.size() - 1);
}
}
}