LeetCode 78. LeetCode78-子集-20200711-java
原题链接
中等
作者:
bmdxyn0725
,
2020-07-11 18:09:47
,
所有人可见
,
阅读 398
class Solution {
List<List<Integer>> res = new ArrayList();
Stack<Integer> path = new Stack();
public List<List<Integer>> subsets(int[] nums) {
for(int i = 0; i <= nums.length; i++){
dfs(nums, 0, i);
}
return res;
}
public void dfs(int[] nums, int u, int k){
if(k==0){
res.add(new ArrayList(path));
return;
}
for(int j = u; j < nums.length; j++){
path.push(nums[j]);
dfs(nums, j+1, k-1);
path.pop();
}
}
}