- Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy path78_Subsets.java
21 lines (18 loc) · 665 Bytes
/
78_Subsets.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
classSolution {
publicList<List<Integer>> subsets(int[] nums) {
if (nums == null || nums.length == 0) {
returnCollections.emptyList();
}
List<List<Integer>> result = newArrayList<>();
dfs(nums, 0, newArrayList<>(), result);
returnresult;
}
privatevoiddfs(int[] nums, intidx, List<Integer> tempResult, List<List<Integer>> result) {
result.add(newArrayList<>(tempResult));
for (inti = idx; i < nums.length; i++) {
tempResult.add(nums[i]);
dfs(nums, i + 1, tempResult, result);
tempResult.remove(tempResult.size() - 1);
}
}
}