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].

Notes: recursive, in place.

 class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
int size = num.size();
vector<vector<int> > result;
if(size == )
return result;
if(size == ) {
vector<int> per;
per.push_back(num[]);
result.push_back(per);
return result;
} for(int i = ; i < size; i ++) {
int current = num[i];
num.erase(num.begin() + i);
vector<vector<int> > ret = permute(num);
num.insert(num.begin() + i, current);
for(auto item: ret) {
item.insert(item.begin(), current);
result.push_back(item);
}
}
return result;
}
};

Permutations [LeetCode]的更多相关文章

  1. Permutations leetcode java

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

  2. [LeetCode] Backtracking Template for (Subsets, Permutations, and Combination Sum)

    根据issac3 用Java总结了backtracking template, 我用他的方法改成了Python. 以下为template. def backtrack(ans, temp, nums, ...

  3. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

  4. Solution to LeetCode Problem Set

    Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...

  5. [LeetCode] Permutations II 全排列之二

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

  6. [LeetCode] Permutations 全排列

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

  7. Java for LeetCode 047 Permutations II

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

  8. leetcode Permutations II 无重全排列

    作者:jostree  转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...

  9. [Leetcode][Python]47: Permutations II

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 47: Permutations IIhttps://oj.leetcode. ...

随机推荐

  1. [数据结构与算法]栈Stack的多种实现

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. [SAP ABAP开发技术总结]预定义(内置)数据类型

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  3. 二叉树hdu1710

    学习二叉树,看了两天也不明白,唉!acm之路让我体验到要付出巨大的努力,废话不多说,看我网上找到的代码: 此题题意很明确,给你先序遍历,中序遍历,求后序遍历.但代码就让我找不到东西了. http:// ...

  4. 关于dom ready事件

    0.加载完页面,解析完所有标签(不包括执行CSS和JS),并如规范中所说的设置 interactive 和执行每个静态的script标签中的JS,然后触发. 1.没有js,有css,有img,DOMC ...

  5. new的深一步

    new的深一步 new运算符 用于创建对象和条用构造函数 new修饰符 用于隐藏基类中被继承的成员 new约束 用于在泛型声明中约束可能用作类型参数的参数类型 new运算符 用于创建对象和调用构造函数 ...

  6. phpcms 修改后台 主页面的模板

    代码在phpcms/modules/admin/templates/main.tpl.php 在该文件修改就可以修改 phpcms后台管理系统的 首页面.

  7. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

  8. CDN学习笔记一(CDN是什么?)

    CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...

  9. XP_版本

    1. Windows XP sp3 cd 和Windows XP sp3 cd vl的区别?VL的意思是大客户版,就是使用VL的KEY安装的系统是不需要激活的,不带VL的是安装完后需要激活的零售版 2 ...

  10. poj3347Kadj Squares

    链接 这题其实与几何没太大关系,还不错的题目. 参考吴永辉的算法设计书. 用lefi.rigi分别表示正方形在x轴上的投影. 为了避免用小数,把边长都扩大sqrt(2)倍,这样lef1 = 0,rig ...