打错一个变量害死我了……
class Solution {
public:
vector<vector<int> > subsets(vector<int> &S) {
sort(S.begin(), S.end());
vector<vector<int>> res;
vector<int> path;
for (int i = 0; i <= S.size(); ++i)
helper(S, res, i, 0, path);
return res;
}
void helper(vector<int> &S, vector<vector<int>> &res, int count, int start, vector<int> &path) {
if(count == 0) {
res.push_back(path);
return;
}
for (int i = start; i < S.size(); ++i) {
path.push_back(S[i]);
helper(S, res, count - 1, i + 1, path);
path.pop_back();
}
}
};
http://oj.leetcode.com/problems/subsets/