回溯
class Solution {
List<Integer> path = new ArrayList<>();
List<List<Integer>> res = new ArrayList<>();
public List<List<Integer>> subsets(int[] nums) {
dfs(0, nums);
return res;
}
void dfs(int i, int[] nums) {
res.add(new ArrayList<>(path));
for (int j = i; j < nums.length; j++) {
path.add(nums[j]);
dfs(j + 1, nums);
path.remove(path.size() - 1);
}
}
}