Leetcode Permutations
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].
使用递归解决
class Solution {
public:
vector<bool> visit;
vector<int> num;
vector<vector<int> > res;
void dfs(int index , vector<int>& sub){
if(index == num.size()){
res.push_back(sub);
return;
}
for(int i = ; i < num.size(); ++ i){
if(!visit[i]){
visit[i] = true;
sub[index] = num[i];
dfs(index+, sub);
visit[i] = false;
}
}
}
vector<vector<int> > permute(vector<int> &num) {
this->num = num;
visit.resize(num.size(),false);
vector<int> sub(num.size(),);
dfs(,sub);
return res;
}
};
Leetcode Permutations的更多相关文章
- leetcode Permutations II 无重全排列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4051169.html 题目链接:leetcode Permutations II 无重全排 ...
- [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 ...
- [leetcode]Permutations II @ Python
原题地址:https://oj.leetcode.com/problems/permutations-ii/ 题意: Given a collection of numbers that might ...
- [leetcode]Permutations @ Python
原题地址:https://oj.leetcode.com/problems/permutations/ 题意: Given a collection of numbers, return all po ...
- LeetCode: Permutations 解题报告
Permutations Given a collection of numbers, return all possible permutations. For example,[1,2,3] ha ...
- [Leetcode] Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- LeetCode:Permutations, Permutations II(求全排列)
Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...
- LeetCode:Permutations(求全排列)
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
随机推荐
- [UML]UML系列——类图Class
相关文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend) 一.类图的概念及组成 1.类图的概念 类图是描述类.接 ...
- 如何处理 在html中 li 的高度自适应(且li里面的内容有浮动的情况下)
废话不多说,我们写贴出代码 这个是 Html 代码 <div class="main"> <ul> <li> <div class=&qu ...
- golang笔记——struct
1.定义一个结构体 type User struct { userid int username string password string } 2.初始化一个结构体 有两种情况,一是得到结构体的对 ...
- [Linux] 账户管理命令(二)
组管理 1)groupadd 用于添加一个用户组. 格式:groupadd [-g -o GID] GROUP 其中: GROUP:是要添加的组名 -g:用于指定 GID,默认为使用当前最大的 ...
- 【总结1】PhpStorm配置XDebug(远程)调试PHP
配置PhpStorm调试PHP 第一步:配置 XDebug 下载安装XDebug到本地环境,打开php.ini,参考配置如下: [XDebug] zend_extension = "D:\P ...
- ORACLE "ORA--22992:无法使用远程表选择的LOB定位器,database link"
解决办法: 先创建一个临时表,然后把远程的含CLOB字段的表导入到临时表中,再倒入本表. create global temporary table demo_temp as select * ...
- 坑爹的私有API
iOS私有API扫描工作总结 背景 苹果提供的iOS开发框架分PrivateFramework和Framework,PrivateFramework下的库是绝对不允许在提交的iOS应用中使用的,只允许 ...
- java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...
- angular自己最近学的一种筛选方法
投资状态vm.statusList = [ {name:"项目状态",value:-1}, {name:"上线",value:0}, {name:"投 ...
- python function parameter
Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...