//注意sort , 使用used
class Solution {
private:
vector<vector<int>> result;
vector<int> path;
void backTracking(vector<int>& nums, int startIndex, vector<bool> used);
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums)
{
vector<bool> used(nums.size());
sort(nums.begin(), nums.end());
backTracking(nums, 0, used);
return result;
}
};
inline void Solution::backTracking(vector<int>& nums, int startIndex, vector<bool> used)
{
result.push_back(path);
for (int i = startIndex; i < nums.size(); ++i)
{
if (i > 0 && nums[i] == nums[i - 1] && used[i -1] == false)
continue;
path.push_back(nums[i]);
used[i] = true;
backTracking(nums, i + 1, used);
used[i] = false;
path.pop_back();
}
}