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. GUI自动化模块化实现方式

    效率为王:脚本与数据的解耦 + Page Object模型 1.数据驱动:实现了“测试脚本和数据的解耦”,数据驱动测试的数据文件中不仅可以包含测试输入数据,还可以包含测试验证结果数据,甚至可以包含测试 ...

  2. 【bzoj3261】最大异或和

    就是一个可持久化Trie....... #include<bits/stdc++.h> #define N 600005 using namespace std; inline int r ...

  3. mysql分页查询语法

    一.limit语法 SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset LIMIT 子句可以被用于强制 SELECT 语句返回指 ...

  4. Eclipse SVN还原文件到历史版本详解

    由于某些特殊原因,我们可能需要将SVN资源库中的某个文件回滚到以前的某个历史版本(准确地说,这不是"回滚","回滚"操作会导致指定版本到当前版本的变更记录丢失, ...

  5. Selenium2+python自动化24-js处理富文本(带iframe)【转载】

    前言 上一篇Selenium2+python自动化23-富文本(自动发帖)解决了富文本上iframe问题,其实没什么特别之处,主要是iframe的切换,本篇讲解通过js的方法处理富文本上iframe的 ...

  6. poj 3608(旋转卡壳求解两凸包之间的最短距离)

    Bridge Across Islands Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9768   Accepted: ...

  7. 转怎么让VI支持中文显示

    https://blog.csdn.net/kayneo/article/details/72957475

  8. [BZOJ4556][Tjoi2016&Heoi2016]字符串 主席树+二分+倍增+后缀自动机

    4556: [Tjoi2016&Heoi2016]字符串 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1215  Solved: 484[S ...

  9. 使用 gulp 压缩 CSS

    请务必理解如下章节后阅读此章节: 安装 Node 和 gulp 使用 gulp 压缩 JS 压缩 css 代码可降低 css 文件大小,提高页面打开速度. 我们接着将规律转换为 gulp 代码 规律 ...

  10. redhat 安装 setuptools【成功】

    1. wget --no-check-certificate http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py ...