vector<vector<int>> r1;
vector<int> r2;
void dfs(int cur, int start, int len, vector<int> &nums) {
if (cur == len)
{
r1.push_back(r2);
return;
}
for (int i = start; i < nums.size(); i++) {
//这句判断用于去重,如[1,1]。如果不加这句话,当len=1时,会输出两个为1的vector
if (i > 0 && nums[i] == nums[i - 1] && i != start)
continue;
r2.push_back(nums[i]);
dfs(cur + 1, i + 1, len, nums);
r2.pop_back();
}
}
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
sort(nums.begin(), nums.end());
for(int i = 0;i <= nums.size();i++)
dfs(0, 0, i,nums);
return r1;
}