-
Notifications
You must be signed in to change notification settings - Fork 6
/
Subsets.cpp
37 lines (37 loc) · 1.01 KB
/
Subsets.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
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector<vector<int>> result;
// // a S1, a
int sz = 0;
for(int i = 0; i < nums.size(); i++)
{
sz = result.size();
for(int k = 0; k < sz; k++)
{
auto temp = result[k];
temp.push_back(nums[i]);
result.push_back(temp);
}
vector<int> c(1,nums[i]);
result.push_back(c);
}
vector<int> c;
result.push_back(c);
// int pw = pow(2, nums.size());
// for(int i=0; i<pw; i++)
// {
// bitset<10> b(i);
// vector<int> current;
// current.resize(b.count());
// int ct = 0;
// for(int i=0; i<nums.size(); i++)
// {
// if(b[i])
// current[ct++] = nums[i];
// }
// result.push_back(current);
// }
return result;
}
};