```
class Solution {
public:
void permutation(set<vector<int> > &all, vector<int> num, int s, int e)
{
if(s==(e+1))
{
all.insert(num);
return;
}
for(int i=s; i<=e; i++)
{
//swap num[i] and num[s]
int tmp = num[i];
num[i] = num[s];
num[s] = tmp;
permutation (all, num, s+1, e);
//swap num[i] and num[s]
tmp = num[i];
num[i] = num[s];
num[s] = tmp;
}
}
vector<vector<int> > permuteUnique(vector<int> &num) {
int n = num.size();
vector<vector<int> > ans;
if(!n)
return ans;
set<vector<int> > all;
permutation(all, num, 0, n-1);
set<vector<int> >::iterator it;
for(it=all.begin(); it != all.end(); it++)
{
ans.push_back(*it);
}
}
};
```