46. Permutations

题目

 Given a collection of distinct 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],
[3,2,1]
]

解析

class Solution_46 {
public:
void help(int i,vector<int> &nums,vector<vector<int>> &vecs)
{ if (i==nums.size())
{
vecs.push_back(nums);
return;
}
else
{
for (int j = i; j < nums.size();j++)
{
swap(nums[i],nums[j]);
help(i + 1, nums,vecs);
swap(nums[i],nums[j]);
}
}
return;
} vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> vecs; if (nums.size()==0)
{
return vecs;
} help(0, nums,vecs); return vecs;
}
};

题目来源

46. Permutations 排列数的更多相关文章

  1. 刷题46. Permutations

    一.题目说明 题目是46. Permutations,给一组各不相同的数,求其所有的排列组合.难度是Medium 二.我的解答 这个题目,前面遇到过类似的.回溯法(树的深度优先算法),或者根据如下求解 ...

  2. SCU 4424(求子集排列数)

    A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice ...

  3. 【一天一道LeetCode】#46. Permutations

    一天一道LeetCode系列 (一)题目 Given a collection of distinct numbers, return all possible permutations. For e ...

  4. 31. Next Permutation + 46. Permutations + 47. Permutations II + 60. Permutation Sequence

    ▶ 问题:字典序生成有关的问题. ▶ 31. 由当前序列生成字典序里的下一个序列. ● 初版代码,19 ms class Solution { public: void nextPermutation ...

  5. LeetCode - 46. Permutations

    46. Permutations Problem's Link -------------------------------------------------------------------- ...

  6. 由abcd四个字符取5个作允许重复的排列,要求a出现次数不超过2次,但不能不出现;b不超过1个;c不超过3个;d出现的次数为偶数。求满足以上条件的排列数。

    一.我的解法       由于没复习,我在想一般的方法,那就是d取0.2.4,然后分步计算,得到225这个错误答案. 二.指数型母函数       设满足以上条件取个排列的排列数为,的指数型母函数为 ...

  7. [Leetcode][Python]46: Permutations

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 46: Permutationshttps://leetcode.com/pr ...

  8. 乘法原理,加法原理,多重集的排列数(多个系列操作穿插的排列数) 进阶指南 洛谷p4778

    https://www.luogu.org/problemnew/solution/P4778 非常好的题目,囊括了乘法加法原理和多重集合排列,虽然最后使用一个结论解出来的.. 给定一个n的排列,用最 ...

  9. 排列数与For的关系

    目录 什么是排列数 用现实模型表示 用Python编程表示 用数学符号表示 规律 规律1 规律2 如果m < n 会怎样? 排列数的应用场景 什么是排列数 排列指将一个集合里的每个元素不重复的排 ...

随机推荐

  1. css的@符号的作用简单介绍

  2. pandas 读写sql数据库

    如何从数据库中读取数据到DataFrame中? 使用pandas.io.sql模块中的sql.read_sql_query(sql_str,conn)和sql.read_sql_table(table ...

  3. ubuntu下wireshark+scapy+tcpreply

    安装wireshark命令: sudo apt-get install wireshark 运行打开wireshark命令: sudo wireshark(一定要以超级权限打开) 正确打开的窗口应该默 ...

  4. C# for Hbase 实现详解

    一共两种方式访问 通过Thrift访问 目前hbase src.tar.gz压缩包中包含thrift he thrift2; 根据官方文档,thrift可能被抛弃,但是网上基本上都是介绍thrift的 ...

  5. sping PropertyPlaceholderConfigurer

    例如,要载入配置文件中的mysql配置信息: jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mypage ...

  6. 本地配置环境打开项目出现404/本地wampserver配置伪静态以及php.ini配置

    本地wamp/phpstudy实现虚拟主机后,出现了500错误看日志看到.htaccess: Invalid command ‘RewriteEngine’, perhaps misspelled o ...

  7. [linux]多线程下载

    axel -n 10 -o /tmp/ http://soft.vpser.net/lnmp/lnmp0.7-full.tar.gz # 10是线程数

  8. JNI基础学习

    1.JNI(Java Native Interface): 它允许Java代码和其他语言写的代码进行交互,JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是它并不妨碍你使用其他语言,只要 ...

  9. Counting Haybales (线段树)

    Counting Haybales 时间限制: 50 Sec  内存限制: 256 MB提交: 52  解决: 18[提交][状态][讨论版] 题目描述 Farmer John is trying t ...

  10. 理解XML-RPC

    有关XML-RPC http://baike.baidu.com/link?url=ejidFtjelUzPv75VBm5_XrzSbHtFgArYY47S1s1NK2_m-auOr10sTeRh6U ...