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]
找全排列,DFS的一般应用
- class Solution {
- public:
- void DFS(vector<int> &num, int size,vector<int> temp)
- {
- if(size == n){
- result.push_back(temp);
- return ;
- }
- for(int i = ; i< n; i++)
- {
- if(flag[i] == false)
- {
- temp[size] = num[i];
- flag[i] = true;
- DFS(num, size+, temp);
- flag[i] = false;
- }
- }
- }
- vector<vector<int> > permute(vector<int> &num) {
- // Start typing your C/C++ solution below
- // DO NOT write int main() function
- n = num.size();
- result.clear();
- flag.resize(n,false);
- if(n == ) return result;
- vector<int> temp(n,) ;
- DFS(num,,temp);
- return result ;
- }
- private :
- int n;
- vector<bool> flag;
- vector<vector<int>> result;
- };
LeetCode_Permutations的更多相关文章
- LeetCode_Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- Powershell使用管道
管道并不是什么新事物,以前的Cmd控制台也有重定向的命令,例如Dir | More可以将结果分屏显示.传统的Cmd管道是基于文本的,但是Powershell是基于对象. PS> ls | Sor ...
- C#读取文件高效方法实现
C# Code 12345678910111213141516171819202122232425262728293031 private void button1_Click ...
- MySQL数学函数
官方文档:Numeric Functions and Operators Name Description ABS() Return the absolute value ACOS() Return ...
- Linux开发工具的使用
1. Linux开发工具的使用 Vim编译的使用 Gdb调试工具的使用 Makefile的编写 linux跟踪调试 SSH的使用 subversion的使用 1. Linux开发工具的使用 V ...
- ASP.NET文件组成(转载于Owen的BLOG)
一.扩展名: .aspx:窗体文件,为前台程序. .cs文件:类文件,主要为后台数据处理,供所有的.aspx文件的后台应用. .asmx文件:用于创建从其他应用程序使用的web服务的类. .css文件 ...
- 什么是 docker?
关于 Docker 是什么,有个著名的隐喻:集装箱.但是它却起了个“码头工人”( docker 的英文翻译)的名字.这无疑给使用者很多暗示:“快来用吧!用了 Docker ,就像世界出现了集装箱,这样 ...
- 5 c语言数组
其中包括:冒泡 高精度加法 统计不相同的数字个数(数组) 数组元素倒序输出 go~~~~ #include <stdio.h> /* 功能:冒泡 时间:2016.11.15 */ void ...
- poj 3273 Monthly Expense(二分搜索之最大化最小值)
Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) ...
- 执行testng appium用例失败,自动截图
新建一个截图监听类ScreenShotListener ,重写onTestFailure方法,里面定义了 监听的driver ,截图文件路径和名称 package com.fsssc.htsgl.ut ...
- javascript对象的理解
从代码中体会javascript中的对象: <!DOCTYPE html> <html> <head> <meta charset="utf-8&q ...