leetcode 46. Permutations
来源:互联网 发布:node.js 微信 编辑:程序博客网 时间:2024/06/06 05:07
class Solution {
public:
vector<vector<int>> res;
int *x;
void helper(vector<int> nums,int t)
{
if(t>=nums.size())
{
vector<int> re;
for(int i=0;i<=nums.size()-1;i++){
re.push_back(x[i]);
cout<<x[i];
}
cout<<endl;
res.push_back(re);
return;
}
else
{
for(int i=0;i<=nums.size()-1;i++)
{
x[t]=nums[i];
bool k=true;
for(int j=0;j<=t-1;j++)
if(x[t]==x[j]){
k=false;
break;
}
if(k) helper(nums, t+1);
}
}
}
vector<vector<int>> permute(vector<int>& nums) {
int size=(int)nums.size();
x=(int*)malloc(sizeof(int)*size);
helper(nums, 0);
return res;
}
};
class Solution {
public:
vector<vector<int>> res;
void helper(vector<int> nums,vector<int> &path,int t,vector<bool> used)
{
if(t>=nums.size())
{
for(int j=0;j<=path.size()-1;j++)
cout<<path[j];
cout<<endl;
res.push_back(path);
return;
}
for(int i=0;i<=nums.size()-1;i++)
{
if(used[i]==true)
continue;
path.push_back(nums[i]);
used[i]=true;
helper(nums, path, t+1, used);
path.pop_back();
used[i]=false;
}
}
vector<vector<int>> permute(vector<int>& nums) {
int size=(int)nums.size();
vector<bool> used (size,false);
vector<int> path;
helper(nums, path,0, used);
returnres;
}
};
- [LeetCode]46.Permutations
- LeetCode 46.Permutations
- 46. Permutations Leetcode Python
- LeetCode --- 46. Permutations
- [Leetcode] 46. Permutations
- [leetcode] 46.Permutations
- LeetCode 46. Permutations DFS
- 46. Permutations LeetCode
- Leetcode 46. Permutations
- leetcode 46. Permutations
- LeetCode *** 46. Permutations
- LeetCode 46. Permutations
- leetcode 46. Permutations
- LeetCode - 46. Permutations
- 【leetcode】46. Permutations
- leetcode 46. Permutations
- [LeetCode] 46. Permutations
- leetcode 46. Permutations
- 微软认知工具Cognitive Toolkit 2.0 完整版发布!速度是对手的3倍
- 第七周 【项目5 -排队看病模拟】
- 素数环
- 前缀式计算 ACM 数据结构
- MOOC-Python网络爬虫与信息提取-第二周 BeautifulSoup库入门与信息提取方法
- leetcode 46. Permutations
- 什么是腾讯安全探索论坛(TSec)?
- 有了《网络安全法》,个人信息就更加安全了吗?
- 黄仁勋说摩尔定律已死,Nvidia要用人工智能应对
- luogu1131 [ZJOI2007][时态同步]
- 折纸问题(递归java)
- 如何快速转发CSDN博客
- JDK动态代理
- fiddler网络抓包神器的使用介绍