import java.io.*;
import java.util.*;
class myCode
{
public List<Integer> subset( int[] nums ){
List<Integer> ans = new ArrayList<Integer>();
helper(nums, 0, ans, 1);
return ans;
}
public void helper(int[] nums, int idx, List<Integer> ans, int product){
if(idx == nums.length) {
return;
}
ans.add(nums[idx]*product);
helper(nums, idx+1, ans, product);
helper(nums, idx+1, ans, nums[idx]*product);
return;
}
public static void main (String[] args) throws java.lang.Exception
{
myCode test = new myCode();
int[] nums = {2,3, 4};
List<Integer> ans = test.subset(nums);
for(int n : ans){
System.out.println(n );
}
}
}
`
网友评论