import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test9 {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>();
nums.add(1);
nums.add(2);
nums.add(3);
nums.add(4);
nums.add(5);
List<List<Integer>> result = subsets(nums);
System.out.println(result);
System.out.println("length:" + result.size());
}
public static List<List<Integer>> subsets(List<Integer> nums) {
if (nums.size() == 0) return Arrays.asList(new ArrayList[]{new ArrayList<Integer>()});
System.out.println("nums:" + nums);
Integer currentNums = nums.get(nums.size() - 1);
System.out.println("currentNums:" + currentNums);
nums.remove(nums.size() - 1);
List<List<Integer>> res = subsets(nums);
List<List<Integer>> res2 = new ArrayList<>();
System.out.println("===============================");
for (List<Integer> re : res) {
List<Integer> r = new ArrayList<>();
if (re.size() != 0) {
for (Integer integer : re) {
r.add(integer);
}
}
System.out.println(r);
res2.add(r);
}
System.out.println("===============================");
int size = res.size();
for (int i = 0; i < size; i++) {
List<Integer> integers = res.get(i);
integers.add(currentNums);
res2.add(integers);
}
System.out.println("result:" + res2);
return res2;
}
}
11-23
1181
04-03
374