-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path78.子集.java
32 lines (29 loc) · 857 Bytes
/
78.子集.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.ArrayList;
import java.util.List;
/*
* @lc app=leetcode.cn id=78 lang=java
*
* [78] 子集
*/
class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<List<Integer>>();
List<Integer> itemList = null;
List<Integer> newItemList = null;
result.add(new ArrayList<Integer>());
int size = 0;
for(int i = 0; i < nums.length; i++){
size = result.size();
for(int j = 0; j < size;j++){
itemList = result.get(j);
newItemList = new ArrayList<>();
if(itemList.size()>0){
newItemList.addAll(itemList);
}
newItemList.add(nums[i]);
result.add(newItemList);
}
}
return result;
}
}