//此题为LeetCode全排列系列的第一题,
class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> res;
vector<int> temp;
backtrack(nums,temp,res);
return res;
}
void backtrack(vector<int>&nums,vector<int>&temp,vector<vector<int>>&res)
{
if(temp.size() == nums.size())
{
res.push_back(temp);
return ;
}
int len = nums.size();
int i = 0;
for(i=0;i<len;i++)
{
if(find(temp.begin(),temp.end(),nums[i]) != temp.end())
continue ;
temp.push_back(nums[i]);
backtrack(nums,temp,res);
temp.pop_back();
}
}
};
//此题解使用的回溯算法的基本思想,很容易解决