Permutations [LeetCode]
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]的更多相关文章
- Permutations leetcode java
题目: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the f ...
- [LeetCode] Backtracking Template for (Subsets, Permutations, and Combination Sum)
根据issac3 用Java总结了backtracking template, 我用他的方法改成了Python. 以下为template. def backtrack(ans, temp, nums, ...
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
- Solution to LeetCode Problem Set
Here is my collection of solutions to leetcode problems. Related code can be found in this repo: htt ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- Java for LeetCode 047 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- leetcode Permutations II 无重全排列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...
- [Leetcode][Python]47: Permutations II
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 47: Permutations IIhttps://oj.leetcode. ...
随机推荐
- hdu 栈题1022&1702
http://acm.hdu.edu.cn/showproblem.php?pid=1022 http://blog.csdn.net/swm8023/article/details/6902426此 ...
- 1.mybatis简介
mybatis简介 MyBatis 是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为My ...
- 未能加载文件或程序集xxx或它的某一个依赖项 试图加载格式不正确的程序
解决方案:IIS——应用程序池——高级设置——启用32位应用程序 :true.
- CSS笔记(四)文本
CSS 文本属性可定义文本的外观.通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本和对文本进行缩进,等等. 参考:http://www.w3school.com.cn/css/css_t ...
- win8和ubuntu双系统安装
做了一个windows和Ubuntu双系统,参考了一些文章.网上资料不少,我就不重复了. 虽然没什么难度,但是有些细节在装的时候需要注意.不然造成资料丢失,系统崩溃,你就得不偿失,需要折腾花费较长的时 ...
- Android下利用SQLite数据库实现增删改查
1: 首先介绍如何利用adb查看数据库 1: adb shell 2: cd /data/data/包名/databases 3: sqlite3 数据库 4 接下来就可以进行数据库的sql语法 ...
- 改变bootstarp图标水平方向
我一开始是以为bootstarp已经自定义了方向的类的,但是我查阅了好久都没有看到,我这里用的是CSS3的旋转180° 1:HTML <i class="icon-thumbs-dow ...
- php按条件查询的数据分页显示,点击下一页时又列出全部数据的解决办法
其实很简单,只要把表单提交方式改为get方式就行了,然后调用分页函数: function getpage(&$m,$where,$pagesize=10){ $m1=clone $m;//浅复 ...
- Java JDBC连接数据库 Access连接数据库
1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机),再通过java.lang.Class类的静态方法forName(String classN ...
- caffe中的filler.hpp源码的作用:
filler.hpp文件:(它应该没有对应的.cpp文件,一切实现都是在头文件中定义的,可能是因为filler只分在网络初始化时用到那么一次吧) 1,首先定义了基类:Filler,它包括:一个纯虚函数 ...