Given a collection of numbers, return all possible permutations.

For example,
[1,2,3] have the following permutations:
[1,2,3][1,3,2][2,1,3][2,3,1][3,1,2], and [3,2,1].

使用递归解决

class Solution {
public:
vector<bool> visit;
vector<int> num;
vector<vector<int> > res;
void dfs(int index , vector<int>& sub){
if(index == num.size()){
res.push_back(sub);
return;
} for(int i = ; i < num.size(); ++ i){
if(!visit[i]){
visit[i] = true;
sub[index] = num[i];
dfs(index+, sub);
visit[i] = false;
}
}
} vector<vector<int> > permute(vector<int> &num) {
this->num = num;
visit.resize(num.size(),false);
vector<int> sub(num.size(),);
dfs(,sub);
return res;
}
};

Leetcode Permutations的更多相关文章

  1. leetcode Permutations II 无重全排列

    作者:jostree  转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...

  2. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  3. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  4. [leetcode]Permutations II @ Python

    原题地址:https://oj.leetcode.com/problems/permutations-ii/ 题意: Given a collection of numbers that might ...

  5. [leetcode]Permutations @ Python

    原题地址:https://oj.leetcode.com/problems/permutations/ 题意: Given a collection of numbers, return all po ...

  6. LeetCode: Permutations 解题报告

    Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] ha ...

  7. [Leetcode] Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  8. LeetCode:Permutations, Permutations II(求全排列)

    Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...

  9. LeetCode:Permutations(求全排列)

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

随机推荐

  1. [Unity3D] Normal map、Diffuse map 和 Speculer map

    Normal map : Normal map (法线贴图) 它的作用是模拟出高模上的一些细节纹理,特别是将高模上的圆滑和粗糙度投射到低模上,让低模也有高模的效果. 因为高模的面数非常多,导入引擎后电 ...

  2. [NHibernate]增删改操作

    目录 写在前面 文档与系列文章 添加数据 删除数据 修改数据 添加修改数据 总结 写在前面 上篇文章介绍了nhibernate的基于面向对象的条件查询.对一个项目来说,增删改查是必不可少的,虽然实现方 ...

  3. Sql Server FOR XML PATH

    FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作.那么以一个实例为主 ...

  4. XMPP作为一个工具的意义

    学习XMPP就是拥有位当前应用程序添加实时,推送,社交功能所需的工具.虽然浏览器不支持XMPP通讯,但是我们可以通过BOSH技术解决. 一个XMPP网络包含如下 服务器:为XMPP节提供路由,是否支持 ...

  5. fzoj1314 You are my brother

    题目描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are fam ...

  6. linuxmint 17安装qt5.3.1

    从官方网站上下载的安装包,双击安装即可. 新建项目编译时,出现错误:cannot find -lGL 解决的方法:安装libgl1-mesa-dev,当然在安装时会安装其他的一些依赖包 在命令行中输入 ...

  7. HTML页面去缓存

    在页面中写入: 两种写法: 1. <META HTTP-EQUIV="nocache" CONTENT="no-cache"> 2. <HEA ...

  8. Discuzx系统 CSS 编码规范,CSS属性书写顺序

    1. 属性写在一行内,属性之间.属性名和值之间以及属性与“{}”之间须有空格,例如:.class { width: 400px; height: 300px; }     2. 属性的书写顺序:    ...

  9. PE440

    一些证明,推荐复制入atom观看 首先我们考虑这个T(n)是什么,我们可以列出递归式: (definition:T) T(0) = 1 T(1) = 10 T(n) = 10*T(n-1) + T(n ...

  10. python——连接MySQL数据库

    都是照着说明文档来的,主要是为了以后忘记了能快一点想起来. 1. 连接 安装MySQL的时候,自动按照了Python的模块,如果没有的话,也可以在官网下载. 看什么都不如看代码来得快: import ...