class Solution {
public:
vector<vector<int> > ret;
vector<int> sln;
void DFS(vector<int> &S, int n) {
if (n == S.size()) {
ret.push_back(sln);
return;
}
DFS(S, n + 1);
sln.push_back(S[n]);
DFS(S, n + 1);
sln.pop_back();
}
vector<vector<int> > subsets(vector<int> &S) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ret.clear();
sln.clear();
sort(S.begin(), S.end());
DFS(S, 0);
return ret;
}
};
Small Case: 4ms
Large Case: 40ms
Time: O(2^n)
Space: O(2^n)