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. C# winform开发:Graphics、pictureBox同时画多个矩形

    C#的System.Drawing 命名空间提供了对 GDI+ 基本图形功能的访问 重点在于获取Graphics对象,例如: Graphics g = panel1.CreateGraphics 事实 ...

  2. 海思h264解码库

    海思的dll,解码h264  解码后转出yuv12 dll自己百度下载  hi_h264dec.dll   hi_h264dec_w.dll   调用方法: if (H264Dec.Hi264DecA ...

  3. mysql 递归查询

    1.创建表: DROP TABLE IF EXISTS `t_areainfo`; CREATE TABLE `t_areainfo` ( `id` ) ' AUTO_INCREMENT, `) ', ...

  4. HP滤波原理浅学

    今天偶然看到如果使用eviews做HP滤波,一时好奇,于是找了点资料看看~ 由于纯属自学,没有找到教材,大家姑且一看咯,也不知道对不对哈.

  5. make 和 makefile 的关系

    程序的 编译 和 链接 要先总结 make 和 makefile,就需要先了解下面这个过程: 预编译:也叫预处理,进行一些文本替换工作,比如将 #define 定义的内容,在代码中进行替换: 编译:将 ...

  6. html5页面打包成App - Android或Iphone安装程序

    下载安装前端开发工具:HBuilder 官网下载:http://www.dcloud.io/ 根据官网说明安装 * 打开登录HBuilder,把做好的H5页面通过添加app项目把H5的文件夹加入进来( ...

  7. 清理系统 cmd

    echo 正在清除系统垃圾文件,请稍等......del /f /s /q %systemdrive%*.tmpdel /f /s /q %systemdrive%*._mpdel /f /s /q ...

  8. discuz上传图片提示附件文件无法保存

    两个可能: 1. 服务器文件夹权限不足 discuz附件保存在./data/attachments下,data文件夹的属性要求必须为777 #cd到data的上一级目录然后执行: data 2. 附件 ...

  9. JavaScript方法——call和apply

    1.相同点: a) 产生的效果或作用完全相同: b) 至少有一个参数: c) 第一个参数必须有且是一个对象(Object),因为就是这个家伙偷懒. 2.不同点: 传递参数的方式. 前提: 1.有两个对 ...

  10. C# FromBase64String 解码换行问题

    Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,大家可以查看RFC2045-RFC2049,上面有MIME的详细规范.Base64编码可用于在HTTP环境下传递较长的标识信息.例如 ...