LeetCode 78. Subsets

题目

class Solution {
public:
    vector<vector<int>> ans;
    vector<vector<int>> subsets(vector<int>& nums) {
        
        vector<int> res;
        ans.push_back(res);
        fun(res,nums,0);
        return ans;
    }
    
    
    void fun(vector<int> res,vector<int> nums,int n)
    {
        for(int i=n;i<nums.size();i++)
        {
            res.push_back(nums[i]);
            ans.push_back(res);
            fun(res,nums,i+1);
            res.pop_back();
        }
    }
};
posted @ 2019-11-02 13:10  Shendu.CC  阅读(78)  评论(0编辑  收藏  举报