题解 | #集合的所有子集(一)#

集合的所有子集(一)

https://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9

#include <vector>
class Solution {
public:
    void dfs(vector<vector<int>> & ans, vector<int> &temp, vector<int> S, int n, int start){
        ans.push_back(temp);
        for(int i = start; i < n; i++){
            temp.push_back(S[i]);
            dfs(ans, temp, S, n, i + 1);
            temp.pop_back();
        }
    }
    vector<vector<int> > subsets(vector<int>& S) {
        // write code here
        vector<int> temp;
        vector<vector<int>> ans;
        
        int n = S.size();

        dfs(ans, temp, S, n, 0);
        return ans;
    }
};

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务