全排列 Permutations

class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
sort(nums.begin(),nums.end());
vector<vector<int>> res;
vector<int> path;
trackback(res,path,nums);
return res;
}
void trackback(vector<vector<int>> &res,vector<int> &path,vector<int> &nums)
{
if(path.size() == nums.size())
{
res.push_back(path);
return ;
}
for(auto i:nums)
{
auto pos=find(path.begin(),path.end(),i);
if(pos==path.end())
{
path.push_back(i);
trackback(res,path,nums);
path.pop_back();
}
}
}
};

  

上一篇:Socket编程中的长连接、短链接以及心跳包机制详解


下一篇:mysql - tmp_table_size & max_heap_table_size