先开始没有res.push_back(v);导致少了[]
另 : 比78.子集 多一条判断条件
class Solution {
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
vector<vector<int> > res;
vector<int> v;
res.push_back(v);
sort(nums.begin(), nums.end());
getSub(nums, 0, res, v);
return res;
}
void getSub(vector<int>& nums, int d, vector<vector<int> >& res, vector<int>& v) {
for(int i = d; i < nums.size(); i++) {
if(i > d && nums[i] == nums[i-1]) continue;
v.push_back(nums[i]);
res.push_back(v);
getSub(nums, i+1, res, v);
v.pop_back();
}
}
};