Article From:https://www.cnblogs.com/JTechRoad/p/9060336.html

https://leetcode.com/problems/subsets/description/

class Solution {
public:
    vector<vector<int>> subsets(vector<int>& nums) {
        vector<vector<int>> res;
        res.push_back(vector<int>());
        for (auto n : nums) {
            int sz = res.size();
            for (int i = 0; i < sz; i++) {
                vector<int> v = res[i];
                v.push_back(n);
                res.push_back(v);
            }
        }
        return res;
    }
};

 

Link of this Article: 78. Subsets

Leave a Reply

Your email address will not be published. Required fields are marked *