- class Solution {
- public:
- vector<int>path;
- vector
int> >ans; - void backtracking(vector<int>nums,int star,vector<bool>&flag){
- if(star>=nums.size())return;
- for(int i=star;i
size();i++){ - if(i>0&&nums[i]==nums[i-1]&&flag[i-1]==false)continue;
- path.push_back(nums[i]);
- flag[i]=true;
- ans.push_back(path);
- backtracking(nums,i+1,flag);
- flag[i]=false;
- path.pop_back();
- }
- }
- vector
int>> subsetsWithDup(vector<int>& nums) { - vector<bool>flag(nums.size(),false);
- sort(nums.begin(),nums.end());
- ans.push_back(path);
- backtracking(nums,0,flag);
- return ans;
- }
- };