fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static Set<List<Integer>> subsets(Set<List<Integer>> result, ArrayList<Integer> curr, int[] nums, int idx) {
  11. result.add((List<Integer>)curr.clone());
  12. if(idx < nums.length){
  13. subsets(result, curr, nums, idx + 1);
  14. final ArrayList<Integer> next = (ArrayList<Integer>) curr.clone();
  15. next.add(nums[idx]);
  16. subsets(result, next, nums, idx + 1);
  17. }
  18. return result;
  19. }
  20. public static void main(String[] args){
  21. int[] x = {1,2};
  22. System.out.println(subsets(new HashSet<>(), new ArrayList<>(), x, 0));
  23. }
  24. }
Success #stdin #stdout 0.07s 32440KB
stdin
Standard input is empty
stdout
[[1], [], [2], [1, 2]]