- subsets
description
class Solution {
public:
vector<vector<int>> subsets(vector<int> &nums) {
vector<vector<int>> res;
vector<int> path;
long pos = -1;
res.push_back(path);
sort(nums.begin(), nums.end());
helper(res, nums, path, pos);
return res;
}
void helper(vector<vector<int>>& res, const vector<int> &nums,
vector<int> path, long pos) {
if (pos == nums.size()) {
return;
}
for (auto i = pos + 1; i < nums.size(); ++i) {
path.push_back(nums[i]);
res.push_back(path);
helper(res, nums, path, i);
path.pop_back();
}
}
};