-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc78.java
More file actions
29 lines (26 loc) · 730 Bytes
/
Lc78.java
File metadata and controls
29 lines (26 loc) · 730 Bytes
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
package leetcode;
import java.util.ArrayList;
import java.util.List;
/**
* @author Kuma
* @date 2021年3月31日
* 78. 子集
*/
public class Lc78 {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
List<Integer> tmp = new ArrayList<>();
backTrack(nums, 0, res, tmp);
return res;
}
public void backTrack(int[] nums, int i,List<List<Integer>> res,List<Integer> tmp){
if (!res.contains(tmp)){
res.add(new ArrayList<>(tmp));
}
for (int j = i; j < nums.length; j++) {
tmp.add(nums[j]);
backTrack(nums,j+1,res,tmp);
tmp.remove(new Integer(nums[j]));
}
}
}