-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL0078_Subsets.java
More file actions
32 lines (25 loc) · 800 Bytes
/
Copy pathL0078_Subsets.java
File metadata and controls
32 lines (25 loc) · 800 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
30
31
32
package leetcode;
import java.util.*;
/**
* @author : zhaochengming
* @date : 2022/5/16 0:20
* @description : https://leetcode.cn/problems/subsets/
*/
public class L0078_Subsets {
static class Solution {
private List<List<Integer>> res = new LinkedList<>();
private void backTrack(int[] nums, int start, Deque<Integer> track) {
res.add(new LinkedList<>(track));
for (int i = start; i < nums.length; i ++) {
track.addLast(nums[i]);
backTrack(nums, i + 1, track);
track.pollLast();
}
}
public List<List<Integer>> subsets(int[] nums) {
Deque<Integer> track = new LinkedList<>();
backTrack(nums, 0, track);
return res;
}
}
}