class Solution {

public:

vector<vector<int>> permuteUnique(vector<int>& nums) {

```
vector<vector<int>> res;
int n = nums.size();
if(n == 0)
return res;
stack <vector<int>> perm;
std::sort(nums.begin(),nums.end());
perm.push(nums);
for(int fix_pos = 0;fix_pos < n - 1;fix_pos++)
{
stack <vector<int>> temp;
vector<int> vec;
while(!perm.empty())
{
vec = perm.top();
perm.pop();
for(int i = fix_pos;i < n;i++)
{
if(i != fix_pos && vec[i] == vec[fix_pos])
continue;
std::swap(vec[i],vec[fix_pos]);
temp.push(vec);
// don't need to retain original string as it will result duplicacy
}
}
std::swap(perm,temp);
}
while(!perm.empty())
{
res.push_back(perm.top());
perm.pop();
}
return res;
}
```

};