-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path78.cpp
25 lines (25 loc) · 780 Bytes
/
78.cpp
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
class Solution {
public:
void dfs(int count, std::vector<int> &nums, int start, std::vector<std::vector<int>> &ans, std::vector<int> &temp) {
if (temp.size() == count) {
ans.push_back(temp);
return;
}
for (int i = start; i < nums.size(); i++) {
if (nums.size() - i + temp.size() < count) {
return;
}
temp.push_back(nums[i]);
dfs(count, nums, i + 1, ans, temp);
temp.pop_back();
}
}
vector<vector<int>> subsets(vector<int>& nums) {
std::vector<std::vector<int>> ans;
for(int i = 0; i <= nums.size(); i++) {
std::vector<int> temp;
dfs(i, nums, 0, ans, temp);
}
return ans;
}
};