给定一个没有重复数字的序列,返回其所有可能的全排列。

示例:

输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]

class Solution {
public:
vector<vector<int> >res;
vector<int> visit;
int size;
vector<vector<int> > permute(vector<int>& nums)
{
int len = nums.size();
if(len == 0)
return res;
size = len;
visit = vector<int>(len, 0);
vector<int> temp;
DFS(nums, temp, 0);
return res;
} void DFS(vector<int>& nums, vector<int> &temp, int len)
{
if(len == size)
{
res.push_back(temp);
}
for(int i = 0; i < size; i++)
{
if(visit[i] == 1)
continue;
visit[i] = 1;
temp.push_back(nums[i]);
DFS(nums, temp, len + 1);
visit[i] = 0;
temp.pop_back();
}
}
};

Leetcode46. Permutations全排列的更多相关文章

  1. [CareerCup] 9.5 Permutations 全排列

    9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...

  2. [LeetCode] Permutations 全排列

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

  3. lintcode 中等题:permutations 全排列

    题目 全排列 给定一个数字列表,返回其所有可能的排列. 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个列表[1,2,3],其全排列为: [ [1,2,3], [1,3,2], [2,1,3 ...

  4. [leetcode]46. Permutations全排列(给定序列无重复元素)

    Given a collection of distinct integers, return all possible permutations. Input: [1,2,3] Output: [ ...

  5. [leetcode]47. Permutations全排列(给定序列有重复元素)

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

  6. 46. Permutations (全排列)

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

  7. LeetCode46. Permutations

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

  8. 046 Permutations 全排列

    给定一个含有不同数字的集合,返回所有可能的全排列.比如,[1,2,3] 具有如下排列:[  [1,2,3],  [1,3,2],  [2,1,3],  [2,3,1],  [3,1,2],  [3,2 ...

  9. [LeetCode] 46. Permutations 全排列

    Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...

随机推荐

  1. Object.keys()应用

    <script type="text/javascript"> var person={ firstName:"David", lastName:& ...

  2. 使用WCF上传文件

              在WCF没出现之前,我一直使用用WebService来上传文件,我不知道别人为什么要这么做,因为我们的文件服务器和网站后台和网站前台都不在同一个机器,操作人员觉得用FTP传文件太麻 ...

  3. python生成word中文字体

    python生成word中文字体 我们今天用python生成word文件,主要是用到了PyRTF包生成rtf文件,由于PyRTF的包中文教程比较少,所以特此记录几篇文章,也希望给大家有一些帮助. 开始 ...

  4. 立体声耳机接口3F07

    仅探讨三段式 剩余的两根,则是开关,插入耳机后,会断开,可以用于耳机和扬声器的切换.老式收音机大多采用这个结构

  5. 01_Spring入门程序

    一.什么是Spring? 1.Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 2.spring是一个高度灵活的轻量级框架,其目的是降低企业级应用开发的复杂度. ...

  6. IntelliJ IDEA community 安装教程

    jetbrains官网下载 IntelliJ IDEA安装包 https://www.jetbrains.com/idea/download/#section=windows 此处选择社区版的zip文 ...

  7. C# 把十六进制表示的ASCII码转换为对应的字符组成的字符串

    0x30表示字符‘0’的ASCII码.

  8. rabbitmq类

    1.accept.php消费者代码需要在命令行执行 2.'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码 RabbitMQCommand ...

  9. Odoo中使用的部分表名及用途

    res_users 用户res_groups 用户组(角色)res_lang 语言res_partner 供应商/客户/联系人res_font 字体res_company 公司res_bank 银行r ...

  10. Django项目:CRM(客户关系管理系统)--83--73PerfectCRM实现CRM模板统一

    {#king_index.html#} {## ————————73PerfectCRM实现CRM模板统一————————#} {% extends "master/sample.html& ...