1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| void helper(vector<vector<int>>& res, vector<int>& A, vector<int>& now, int p) { if(p == A.size()) res.push_back(now); else { now.push_back(A[p]); helper(res,A,now,p+1); now.pop_back(); helper(res,A,now,p+1); } } vector<vector<int>> Solution::subsets(vector<int> &A) { sort(begin(A), end(A)); vector<vector<int>>res; helper(res, A, vector<int>() = {}, 0); sort(begin(res),end(res)); return res; }
|