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. 创立一个网站的前前后后(起因,域名,云平台,备案,CDN等等)(1)

    起因 写完<完美软件开发:方法与逻辑>这书后,原本想继续写书的,可出来参加了些社区活动后,我发现我写的书大家评价还行,但其实不太理解.而接下来想写的书更加抽象点,准备叫<管理的解析& ...

  2. Asp.Net Core--基于角色的授权

    翻译如下: 当创建身份时,它可以属于一个或多个角色,例如Tracy可以属于管理员和用户角色,而Scott可以仅属于用户角色. 如何创建和管理这些角色取决于授权过程的后备存储. 角色通过ClaimsPr ...

  3. 2.4使用属性在 ASP.NET Web API 2 路由创建一个 REST API

    Web API 2 支持一种新型的路由,称为属性路由.属性路由的一般概述,请参阅属性路由 Web API 2 中.在本教程中,您将使用属性路由创建一个 REST API 集合的书.API 将支持以下操 ...

  4. SpringMVC Controller介绍

    SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理 ...

  5. python3 黑板客爬虫闯关游戏(一)

    这是学习python爬虫练习很好的网站,强烈推荐! 地址http://www.heibanke.com/lesson/crawler_ex00/ 第一关猜数字 很简单,直接给出代码 import ur ...

  6. xampp本地配置多域名

    xampp内建apache服务器,也是可以配置vhosts的 1. 打开httpd.conf文件,搜索vhosts 发现这句话: # Virtual hosts Include conf/extra/ ...

  7. C++中的 :: 用法

    ::是运算符中等级最高的,它分为三种:1)global scope(全局作用域符),用法(::name)2)class scope(类作用域符),用法(class::name)3)namespace ...

  8. xss小试

    javascript:alert(document.cookie)javascript:alert(document.domain) 预防: HTTP cookie设置为readOnly 豆瓣 coo ...

  9. 个人Win10 +archlinux安装笔记

    win10+archlinux 1.查看磁盘并分区并挂载1.1 分区/dev/sda1 WIN10 保留分区/dev/sda2 WIN10 ESP分区(EFI)/dev/sda3 WIN10 MSR分 ...

  10. python之OS模块详解

    python之OS模块详解 ^_^,步入第二个模块世界----->OS 常见函数列表 os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows ...