标签:++ https etc href pre public ret perm leetcode
排列组合嘛。
用DFS 递归一下,输出就好了。又不会超时的
class Solution {
public:
vector<vector<int>> ans;
vector<int> res;
int vis[100005];
vector<vector<int>> permute(vector<int>& nums) {
fun(nums,0);
return ans;
}
void fun(vector<int> nums,int num)
{
if(num==nums.size())
{
ans.push_back(res);
return;
}
for(int i=0;i<nums.size();i++)
{
if(vis[i]==0)
{
vis[i]=1;
res.push_back(nums[i]);
fun(nums,num+1);
res.pop_back();
vis[i]=0;
}
}
}
};
标签:++ https etc href pre public ret perm leetcode
原文地址:https://www.cnblogs.com/dacc123/p/11392729.html