Leetcode46. Permutations全排列
给定一个没有重复数字的序列,返回其所有可能的全排列。
示例:
输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
class Solution {
public:
vector<vector<int> >res;
vector<int> visit;
int size;
vector<vector<int> > permute(vector<int>& nums)
{
int len = nums.size();
if(len == 0)
return res;
size = len;
visit = vector<int>(len, 0);
vector<int> temp;
DFS(nums, temp, 0);
return res;
}
void DFS(vector<int>& nums, vector<int> &temp, int len)
{
if(len == size)
{
res.push_back(temp);
}
for(int i = 0; i < size; i++)
{
if(visit[i] == 1)
continue;
visit[i] = 1;
temp.push_back(nums[i]);
DFS(nums, temp, len + 1);
visit[i] = 0;
temp.pop_back();
}
}
};
Leetcode46. Permutations全排列的更多相关文章
- [CareerCup] 9.5 Permutations 全排列
9.5 Write a method to compute all permutations of a string. LeetCode上的原题,请参加我之前的博客Permutations 全排列和P ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- lintcode 中等题:permutations 全排列
题目 全排列 给定一个数字列表,返回其所有可能的排列. 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个列表[1,2,3],其全排列为: [ [1,2,3], [1,3,2], [2,1,3 ...
- [leetcode]46. Permutations全排列(给定序列无重复元素)
Given a collection of distinct integers, return all possible permutations. Input: [1,2,3] Output: [ ...
- [leetcode]47. Permutations全排列(给定序列有重复元素)
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- 46. Permutations (全排列)
Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have t ...
- LeetCode46. Permutations
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
- 046 Permutations 全排列
给定一个含有不同数字的集合,返回所有可能的全排列.比如,[1,2,3] 具有如下排列:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2 ...
- [LeetCode] 46. Permutations 全排列
Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3] O ...
随机推荐
- pyqt点击右上角关闭界面但是子线程仍在运行
现象: 通过右上角的叉关闭图形界面后,程序运行的子线程却不会被自动关闭,依然留存在系统中原因: 子线程没有正确关闭解决方法: 1.将子线程设置成守护线程 self.your_thread = thre ...
- shell对文件,文件夹的操作
x=$ OUTFILENAME="output_${x}.sql" if [ -f $OUTFILENAME ];then rm $OUTFILENAME fi 如果文件存在则删除 ...
- pycharm优化
一.版本选择 建议安装5.0版本,因为好注册,这个你懂得. 下载地址: https://confluence.jetbrains.com/display/PYH/Previous+PyCharm+Re ...
- [原创]mysql 5.6安装配置,主从分离,读写分离简单教程
文章中参考使用了多个博客的资料,汇总而成!其流程准确性被人亦本人实践! https://blog.csdn.net/qq_35206261/article/details/81321201 https ...
- yii2下使用支付宝
最近入坑了yii2 感觉是个很强大的框架.使用yii做支付宝的移动支付的时候出了点问题,记录下来避免以后忘记了. 使用的是支付宝立即到账的功能,网上很多集成好的接口我就不重复了,找不到的话github ...
- DataLossError (see above for traceback): file is too short to be an sstable [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_F
DataLossError (see above for traceback): file is too short to be an sstable [[Node: save/RestoreV2 = ...
- Windows API 第四篇 文件操作
创建或打开文件(也可用于打开管道,油槽,硬件设备等): HANDLE CreateFile( LPCTSTR lpFileName, // file name DWORD dwDesiredAcces ...
- Android 开发 DNK开发将.c文件打包成os
前言 不废话太多,Java与C之间联系的JNI的概念,这个要了解可以参考下面这个博客: https://www.jianshu.com/p/87ce6f565d37 此博客只说明如何将.C文件通过ND ...
- 细说WPF自定义路由事件
WPF中的路由事件 as U know,和以前Windows消息事件区别不再多讲,这篇博文中,将首先回顾下WPF内置的路由事件的用法,然后在此基础上自定义一个路由事件. 1.WPF内置路由事件 W ...
- Innodb_buffer_pool_read
> show status like 'Innodb_buffer_pool_read_%'; +---------------------------------------+-------- ...