class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> result;
result.clear();
if(nums.size()==0)
return result;
int nums_len=nums.size();
for(int i=0;i<nums.size();i++)
{
vector<vector<int>> temp;
result=cha(result,nums[i]);
//result.insert(result.end(),temp.begin(),temp.end());
}
//int result_size=result.size();
return result;
}
vector<vector<int>> charu(vector<int>& nums,int num)
{
vector<vector<int>> result;
if(nums.size()==0)
{
vector<int> t={num};
result.push_back(t);
return result;
}
for(int i=0;i<nums.size()+1;i++)
{
vector<int> copy=nums;
copy.insert(copy.begin()+i,num);
result.push_back(copy);
}
return result;
}
vector<vector<int>> cha(vector<vector<int>> ori,int num)
{
vector<vector<int>> result;
result.clear();
if(ori.size()==0)
{
vector<int> copy={num};
result.push_back(copy);
return result;
}
int ori_len=ori.size();
for(int i=0;i<ori_len;i++)
{
vector<vector<int>> cha;
vector<int> pop_vec=ori[ori.size()-1];
ori.pop_back();
cha=charu(pop_vec,num);
result.insert(result.begin(),cha.begin(),cha.end());
}
return result;
}
};
46 permutation
最新推荐文章于 2020-07-14 14:11:34 发布