# 给定一组不含重复元素的整数数组 nums，返回该数组所有可能的子集

package week_01;

import java.util.ArrayList;
import java.util.List;

/*

[
[3],
[1],
[2],
......
*/
public class Day_1 {

public List<List<Integer>> subsets(int nums[]) {

List<List<Integer>> list_1 = new ArrayList<List<Integer>>();

for (int i = 0; i < nums.length; i++) {
int size = list_1.size();
System.out.println("list_1.size =  " + size + "   " + "list_1 =  " + list_1);
for (int j = 0; j < size; j++) {
List<Integer> temp_list = new ArrayList<>(list_1.get(j));

System.out.print(list_1.get(j) + "   " + "templist  =  " + temp_list + "     ");

System.out.println("templist  =  " + temp_list);

}

System.out.println();
}
return list_1;
}

public static void main(String[] args) {
int arr[] = {1, 2, 3};
//        System.out.println(new Day_1().subsets(arr));
new Day_1().subsets(arr);
}
}
/*
* 运行结果：
list_1.size =  1   list_1 =  [[]]
[]   templist  =  []     templist  =  [1]

list_1.size =  2   list_1 =  [[], [1]]
[]   templist  =  []     templist  =  [2]
[1]   templist  =  [1]     templist  =  [1, 2]

list_1.size =  4   list_1 =  [[], [1], [2], [1, 2]]
[]   templist  =  []     templist  =  [3]
[1]   templist  =  [1]     templist  =  [1, 3]
[2]   templist  =  [2]     templist  =  [2, 3]
[1, 2]   templist  =  [1, 2]     templist  =  [1, 2, 3]
*
*
* [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]*/

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

会飞滴丶土豆

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文

05-23 2152
04-23 142
01-30 152
07-26 901