78. 子集
class Solution {
List<List<Integer>> res;
List<Integer> path;
int[] nums;
public List<List<Integer>> subsets(int[] nums) {
res = new ArrayList<>();
path = new ArrayList<>();
this.nums = nums;
dfs(0);
return res;
}
private void dfs(int index) {
if (index > nums.length) {
return;
}
res.add(new ArrayList<>(path));
for (int i = index; i < nums.length; i++) {
path.add(nums[i]);
dfs(i + 1);
path.remove(path.size() - 1);
}
}
}