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. ...
随机推荐
- CSS3选择器 :nth-child(n) 详解
CSS3 :nth-child(n): http://demo.doyoe.com/css3/nth-child(n)/ 浏览器参照基准:IE9, Firefox, Chrome, Safari, O ...
- [SAP ABAP开发技术总结]OLE
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 【CC评网】2013.第42周 话说时间管理
时间管理 工作几年之后,大家都会有意识的培养时间管理的概念:但如何真正做到位,并持续坚持,并不是一件容易的事: 虽然关注时间管理已有几年,但目前我对于时间的利用并不高效: 理论上的东西就是那些,但真正 ...
- Cocos2d-x优化中纹理优化
转自 http://blog.csdn.net/tonny_guan/article/details/41016241 Cocos2d-x优化中纹理优化 1.纹理像素格式纹理优化工作的另一重要的指标是 ...
- QQMain
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class QQMain extends JFrame ...
- 小度Wifi_设置
PS:现在我用的小度Wifi驱动的 安装程序的版本为:“XiaoduWiFi140923_M_3.0.9.rar”(保存于“百度云 OsSkill --> 软件安装包 > 小度Wifi__ ...
- strcpy, memcpy, memset函数
一. strcpy函数 原型声明:char *strcpy(char* dest, const char *src); 头文件:#include <string.h> 和 #inclu ...
- STM32学习笔记(一) 如何新建一个STM32工程模板
学习stm32,第一步就是选择开发工具了,GCC,MDK,IAR每一种都有自己的优劣势,这里我选择使用MDK软件实现STM32模板.当然如果想更快的接触stm32实例,领略嵌入式开发的魅力,STM也提 ...
- Logger日志级别说明及设置方法、说明 (zhuan)
http://blog.csdn.net/rogger_chen/article/details/50587920 ****************************************** ...
- request is not finfished yet!
在项目测试的时候发现一个问题.当数据量特别多的时候,我一次性查询几万条数据的时候,就会出现很卡很慢的状态. 我把sql优化了,但是出现同样的问题.我要从后台得到数据显示在页面上来.就需要知道是查询慢, ...