class Solution {
public:
vector<vector<int> > subsets(vector<int> &s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
sort(s.begin(),s.end());
int max = 1 << s.size();
vector<vector<int> > results;
for (int i = 0; i < max; ++i) {
int index = 0;
vector<int> result;
int j = i;
while (j > 0) {
if (j&1) {
result.push_back(s[index]);
}
j >>= 1;
++index;
}
results.push_back(result);
}
return results;
}
};
Leetcode: Subsets (Iterative)
最新推荐文章于 2019-08-12 22:32:00 发布