```
void helper(vector<int> &num, int start, vector<vector<int> > &result) {
if (start == num.size() - 1) {
result.push_back(num);
return;
}
for(int k = start; k < num.size(); ++k) {
if (start == k || num[start] != num[k]){
swap(num[start], num[k]);
helper(num, start + 1, result);
swap(num[start], num[k]);
}
}
}
vector<vector<int> > permuteUnique(vector<int> &num) {
sort(num.begin(), num.end());
vector<vector<int> > result;
helper(num, 0, result);
return result;
}
```

Above is my code. It got a Output Limit Exceeded. However, if I changed like this

```
void helper(vector<int> num, int start, vector<vector<int> > &result) {
if (start == num.size() - 1) {
result.push_back(num);
return;
}
for(int k = start; k < num.size(); ++k) {
if (start == k || num[start] != num[k]){
swap(num[start], num[k]);
helper(num, start + 1, result);
}
}
}
vector<vector<int> > permuteUnique(vector<int> &num) {
sort(num.begin(), num.end());
vector<vector<int> > result;
helper(num, 0, result);
return result;
}
```

It accepted!

The two algorithms are the same. I got same outputs on my local machine. But using reference and swap back the elements is better for space. I cannot figure out why. NEED HELP.