class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
permutation(num,0);
return ans;
}
void permutation(vector<int>&num,int index){
if(index==num.size()-1){
ans.push_back(num);
return;
}
for(int i=index;i<num.size();i++)
{
swap(num[index],num[i]);
permutation(num,index+1);
swap(num[index],num[i]);
}
}
private:
vector<vector<int>>ans;
};
网友评论