leetcode78. 子集

分析

优秀题解链接

class Solution {
public:
    vector<vector<int>> ans;
    vector<int>path;
    void dfs(int u,vector<int>& nums){
       ans.push_back(path);
       for(int i=u;i<nums.size();i++){
           path.push_back(nums[i]);
           dfs(i+1,nums);
           path.pop_back();
       }
       return ;
    }
    vector<vector<int>> subsets(vector<int>& nums) {
            dfs(0,nums);
        return ans;
    }
};