LeetCode 78.子集

LeetCode 78.子集_第1张图片

class Solution {
public:
    vector<vector<int>> ans;
    vector<int> tmp;
    void find(int dep, vector<int>& nums)
    {

        if(dep <= 0)
        {
            ans.push_back(tmp);
            return;
        }

        tmp.push_back(nums[dep - 1]);
        find(dep - 1, nums);
        tmp.pop_back();

        find(dep - 1, nums);
    }

    vector<vector<int>> subsets(vector<int>& nums) {
        find(nums.size(), nums);
        return ans;
    }
};

LeetCode 78.子集_第2张图片

你可能感兴趣的:(LeetCode 78.子集)