[InterviewBit] Subset

Subset

  • Time :
  • Space :
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;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/09/23/PS/interviewbit/subset/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.