Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, if S = [1,2,2], a solution is: [ [2], [1], [1,2,2], [2,2], [1,2], [] ].
void subsets(vector<int> vecInt)
{
sort(vecInt.begin(), vecInt.end());
vector<int> vecWorker;
subsetsHelper(vecWorker, vecInt, 0);
}
void subsetsHelper(vector<int>& vecWorker, const vector<int>& vecInt, int pos)
{
outputToResult(vecWorker);
for (int i = pos; i )
{
if (i != pos && vecInt[i] == vecInt[i-1])
continue;
vecWorker.push_back(vecInt[i]);
subsetsHelper(vecWorker, vecInt, i+1);
vecWorker.pop_back();
}
}