java刷题--78子集
Posted Anrys
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java刷题--78子集相关的知识,希望对你有一定的参考价值。
题目
代码
class Solution {
List<List<Integer>> res = new ArrayList<List<Integer>>();
public List<List<Integer>> subsets(int[] nums) {
dfs(0, nums,new ArrayList());
return res;
}
public void dfs(int start, int[] nums, List temp) {
if (start == nums.length) {
res.add(new ArrayList<Integer>(temp));
return;
}
temp.add(nums[start]);
dfs(start + 1, nums,temp);
temp.remove(temp.size() - 1);
dfs(start + 1, nums,temp);
}
}
结果
以上是关于java刷题--78子集的主要内容,如果未能解决你的问题,请参考以下文章