clueless coding // TODO: be smarter

LeetCode Subsets: CPP Solution



TL;DR Code Solution


vector<vector<int>> subsets(vector<int>& nums) {
    vector<vector<int>> result;
    vector<int> current;
    subset(result, nums, current, 0);
    return result;
}

void subset(vector<vector<int>>& result, vector<int>& nums, vector<int> current, int index) {

    result.push_back(current);
    for (int i = index; i < nums.size(); i++) {
        current.push_back(nums[i]);
        subset(result, nums, current, i + 1);
        current.pop_back();
    }

}