leetcode(78)subset
public class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> results = new ArrayList<>();if (nums == null || nums.length == 0) {
return results;}List<Integer> subset = new ArrayList<>();dfsHelper(nums, 0, results, subset);return results;}private void dfsHelper(int[] nums, int startIndex, List<List<Integer>> results, List<Integer> subset) {
results.add(new ArrayList<>(subset));for (int i = startIndex; i < nums.length; i++) {
subset.add(nums[i]);dfsHelper(nums, i + 1, results, subset);subset.remove(subset.size() - 1);} }
}
我的主页