标签:des style blog http io ar color os sp
Given a set of distinct integers, S, return all possible subsets.
Note:
For example,
If S = [1,2,3]
, a solution is:
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
Array Backtracking Bit Manipulation
class Solution { private: vector<vector<int> > ret; public: void generate(vector<int> vet,vector<int> &S,int i){ if(i==S.size()){ ret.push_back(vet); return; } generate(vet,S,i+1); //相当于取右子树 vet.push_back(S[i]); generate(vet,S,i+1); //相当于取左子树 } vector<vector<int> > subsets(vector<int> &S) { ret.clear(); sort(S.begin(),S.end()); vector<int> vet; generate(vet,S,0); return ret; } };
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/li303491/p/4111860.html