[LEETCODE] Subsets
LINK:http://leetcode.com/onlinejudge#question_78
题意:给出一个数组, 求其子集。
class Solution {
public:
    vector<vector<int> > ans;
    void dfs(vector<int> &S, int now, vector<int> t){
        if(now >= S.size()){
            sort(t.begin(),t.end());
            ans.push_back(t);
            return;
        }
        dfs(S, now + 1, t);
        t.push_back(S[now]);
        dfs(S, now + 1, t);
    }
    vector<vector<int> > subsets(vector<int> &S) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        ans.clear();
        vector<int> t;
        dfs(S, 0, t);
        return ans;
    }
};
每次总感觉自己的DFS写的很怂的样子.
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号