-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path78-subsets.cpp
More file actions
52 lines (49 loc) · 1.03 KB
/
78-subsets.cpp
File metadata and controls
52 lines (49 loc) · 1.03 KB
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
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution
{
public:
vector<vector<int>> subsets(vector<int> &nums)
{
vector<vector<int>> subs;
}
void buildSubset(vector<int> &nums, int idx, vector<int> &curSub, vector<vector<int>> &allSubs)
{
if (idx <= 0)
{
allSubs.push_back(curSub);
return;
}
else
{
buildSubset(nums, idx, curSub, allSubs);
buildSubset(nums, idx + 1, curSub, allSubs);
}
}
};
void print_matrix(vector<vector<int>> matrix)
{
for (int i = 0; i < matrix.size(); i++)
{
cout << "[ ";
for (int j = 0; j < matrix[i].size(); j++)
{
if (j > 0)
{
cout << ", ";
}
cout << matrix[i][j];
}
cout << " ]" << endl;
}
}
int main()
{
Solution s;
vector<int> v = {1, 2, 3};
vector<vector<int>> subs = s.subsets(v);
print_matrix(subs);
return 0;
}