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());
vector<vector<int> > ret;
ret.push_back(vector<int>());
list<vector<int> > midList;
for(int i = 0; i < S.size(); ++i)
{
midList.push_back(vector<int>());
midList.back().push_back(S.at(i));
}
while(midList.size()>0){
vector<int>& tmp=midList.front();
ret.push_back(tmp);
vector<int>::iterator it=find(S.begin(),S.end(),tmp.back());
while(++it!=S.end()){
midList.push_back(tmp);
midList.back().push_back(*it);
}
midList.pop_front();
}
return ret;
}
};
Leetcode: Subsets
最新推荐文章于 2019-07-27 20:45:00 发布