> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/subsets_ii/recursive.md).

# Recursive

//参考 <http://www.cnblogs.com/felixfang/p/3775712.html>

class Solution {

public:

vector\<vector\<int>> ret;

vector\<int> path;

vector\<vector\<int>> subsetsWithDup(vector\<int>& nums) {

sort(nums.begin(), nums.end());

helper(nums,0);

return ret;

}

void helper(vector\<int>& nums, int step){

if(step==nums.size()){

ret.push\_back(path);

return;

}

//consider both case: add S\[start] into v; not add S\[start] to v.

if(path.size() == 0 || nums\[step]!=path\[path.size()-1])

helper(nums,step+1);

//If S\[start] == v\[v.size()-1], we only need to consider the case add S\[start] into v.

path.push\_back(nums\[step]);

helper(nums,step+1);

path.pop\_back();

}

};
