腾讯五十题No.22 子集
题目链接
看来还得读写几个题才会有感觉
力扣的大佬是真的多
class Solution {
List<List<Integer>> res;
List<Integer> path;
public List<List<Integer>> subsets(int[] nums) {
res = new ArrayList<>();
path = new ArrayList<>();
res.add(new ArrayList<>(path));
dfs(nums,0);
return res;
}
public void dfs(int[] nums,int start){
//i每次的值都为上一次递归中加1下来的值
for(int i = start;i < nums.length;i++){
path.add(nums[i]);
res.add(new ArrayList<>(path));
dfs(nums,i + 1);
path.remove(path.size() - 1);
}
}
}

本文来自博客园,作者:蹇爱黄,转载请注明原文链接:https://www.cnblogs.com/jianjiana/p/15868522.html

浙公网安备 33010602011771号