leetcode 78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.
Example:
Input: nums =
Output:
[
,
,
,
,
,
,
,
[]
]
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List <Integer> > res = new ArrayList();
helper(0, nums, new ArrayList<Integer>(), res);
return res;
}
public void helper(int index, int[]nums, List<Integer> cur, List<List<Integer>> res){
res.add(new ArrayList<>(cur));
for(int i = index; i < nums.length; i++){
cur.add(nums);
helper(i+1, nums, cur,res);
cur.remove(cur.size() -1);
}
}
}
页:
[1]