leetcode - Subsets
2013-11-10 10:22 张汉生 阅读(149) 评论(0) 编辑 收藏 举报
1 class Solution { 2 public: 3 vector<vector<int> > subsets(vector<int> &S) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 sort(S.begin(), S.end()); 6 int n = S.size(); 7 vector<vector<int>> rlt; 8 rlt.push_back(vector<int>()); 9 int i, j; 10 for (i=0; i<n; i++){ 11 int m = rlt.size(); 12 for (j=0; j<m; j++){ 13 vector<int> tmp = rlt[j]; 14 tmp.push_back(S[i]); 15 rlt.push_back(tmp); 16 } 17 } 18 return rlt; 19 } 20 };