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
|
#include <vector>
using std::vector;
class Solution {
public:
void dfs(const vector<int> &nums, int index, int size, vector<int> ¤t,
vector<vector<int>> &result) {
if (index == size) {
result.push_back(current);
return;
}
dfs(nums, index + 1, size, current, result);
current.push_back(nums[index]);
dfs(nums, index + 1, size, current, result);
current.pop_back();
}
vector<vector<int>> subsets(vector<int> &nums) {
vector<int> current;
vector<vector<int>> result;
dfs(nums, 0 , nums.size(), current, result);
return result;
}
};
|