-
Notifications
You must be signed in to change notification settings - Fork 0
/
0078.cpp
45 lines (38 loc) · 816 Bytes
/
0078.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
using namespace std;
class Solution
{
public:
vector<vector<int>> ans;
vector<int> path;
vector<vector<int>> subsets(vector<int>& nums)
{
backtracking(nums, 0);
return ans;
}
// 1. 确定参数
void backtracking(vector<int> nums, int startIndex)
{
// 3. 单次递归处理
ans.push_back(path);
// 2. 确定终止条件
if (startIndex >= nums.size())
return;
// 3. 单次递归处理
for (int i = startIndex; i < nums.size(); i++)
{
path.push_back(nums[i]);
backtracking(nums, i + 1);
path.pop_back();
}
return;
}
};
int main()
{
vector<int> nums = { 1,2,3 };
Solution S;
S.subsets(nums);
return 0;
}