```
class Solution {
public:
vector<vector<int> > subsets(vector<int> &S) {
sort(S.begin(),S.end());
vector<vector<int>> results;
//from less to more
for (unsigned i = 0; i < S.size(); ++i){
vector<vector<int>> append = results;
for (vector<vector<int>>::iterator iter = append.begin(); iter != append.end(); ++iter){
iter->push_back(S[i]);
results.push_back(*iter);
}
vector<int> temp;
temp.push_back(S[i]);
results.push_back(temp);
}
vector<int> emp;
results.push_back(emp);
return results;
}
};
```

basically used dynamic idea, subset of i*th* is subset of (i-1)*th* append each element of subset of (i-1)*th* with S[i] in its tail.

for example {1,2,3,4}

subset of {1,2,3} is {1,2,3,12,13,23,123}

subset of {1,2,3,4} is {1,2,3,12,13,23,123} + {1 **4**,2 **4**,3 **4**,12 **4**,13 **4**,23 **4**,123 **4**} + {**4**}