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. Python学习笔记——集合类型

    集合类型有两种不同的类型——可变集合(set)和不可变集合(frozenset) 可变集合不是可哈希的,不能用作字典的键,也不能用做其他集合中的元素 不可变集合是有哈希值的,能被用做字典的键或者是作为 ...

  2. C#内存管理与垃圾回收

    垃圾回收还得从根说起,就像生儿育女一样. 根:根是一个位置,存放一个指针,该指针指向托管堆中的一个对象,或是一个空指针不指向任何对象,即为null.根存在线程栈或托管堆中,大部分的跟都在线程栈上,因为 ...

  3. thinkphp3.2与phpexcel基础生成

    public function ff(){ import("Org.Util.PHPExcel"); import("Org.Util.PHPExcel.Workshee ...

  4. Git入门

    转: http://www.cnblogs.com/luxiaojun/p/5944145.html

  5. Redis、Memcache和MongoDB的区别(转)

    1.性能 都比较高,性能对我们来说应该都不是瓶颈 总体来讲,TPS方面redis和memcache差不多,要大于mongodb 2.操作的便利性 memcache数据结构单一 redis丰富一些,数据 ...

  6. Spring3.0目录

    (1)Spring 入门知识 (2)IoC/DI基本思想的演变 (3)深入理解IoC/DI (4)Spring的简单demo

  7. vertx verticle

    以下内容为随手记的,若看客不知鄙人所云,还请原谅则个.............. 公司用的vertx,在国内,这还是款比较年轻的框架,你也可以把他当做一个工具,官网上的说法是: Vert.x is a ...

  8. IE 8 下的 box-sizing 和 min-* 属性

    在非 IE 浏览器中,默认情况下 width 属性指的是内容区域(content)的宽度. IE 6+ 中,如果浏览器以标准模型渲染,和非 IE 浏览器的表现是一致的:如果浏览器以怪癖模式渲染,则 w ...

  9. 兼容IE8以下浏览器input表单属性placeholder不能智能提示功能

    当前很多表单提示使用了表单属性placeholder,可这属性不兼容IE8以下的浏览器,我自己写了一个兼容处理js // 兼容IE8以下浏览器input不能智能提示功能 if(navigator.ap ...

  10. window跳转页面

    1.直接的事件跳转 window.location.href="你所要跳转的页面"; 2.新窗口跳转 window.open('你所要跳转的页面'); 3.返回上一页 window ...