Hi All

I am trying to solve the problem is "Permutations".

However, I found

Status: Runtime Error

Last executed input: [0,1]

Could you help me figure out where is the bug?

I could not find it.

It is very likely in the line

for(int j=0; j<n; j++){//???

Thanks in advance

class Solution {

public:

vector<vector<int> > permute(vector<int> &num) {

```
vector<vector<int>> res;
int n=num.size();
if(n==0) return res;
permute(res,num,n);
return res;
}
void permute(vector<vector<int>> &res, vector<int> &num, int n){
if(n==1){
res.push_back(vector<int>(num[0]));
return;
}
permute(res, num, n-1);
int resn = res.size();
vector<int> work;
for(int i=0; i<resn; i++){
for(int j=0; j<n; j++){//???
work = res[i];
work.insert(work.begin()+j,num[n-1]);
res.push_back(work);
work.clear();
}
}
res.erase(res.begin(),res.begin()+resn);
return;
}
```

};