题解 | #没有重复项数字的全排列#
没有重复项数字的全排列
https://www.nowcoder.com/practice/4bcf3081067a4d028f95acee3ddcd2b1
class Solution { public: void permute_(vector<int>& num,vector<vector<int>>& res,int n) { if(n==num.size()-1) res.push_back(num); else { for(int i=n;i<num.size();++i) { swap(num[i],num[n]); permute_(num,res,n+1); swap(num[i],num[n]); } } } vector<vector<int> > permute(vector<int>& num) { sort(num.begin(),num.end()); vector<vector<int>> res; permute_(num,res,0); sort(res.begin(),res.end()); return res; } };