leetcode - Permutations
来源:互联网 发布:ps淘宝 编辑:程序博客网 时间:2024/05/22 01:31
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]
.
分析:就是在一个集合中N个元素按不同顺序取出其元素组成N!个序列
class Solution {public: void mute(vector<vector<int> > &v, vector<int> a, int k, vector<int> &num, vector<bool> b) { int n = num.size(); if(k == 0) { v.push_back(a); return; } for(int i = 0; i < n; i++) { if(b[i] == false) { a.push_back(num[i]); b[i] = true; mute(v,a,k-1,num,b); b[i] = false; a.pop_back(); } } return; } vector<vector<int> > permute(vector<int> &num) { vector<vector<int> > v; int n = num.size(); vector<int> a; vector<bool> IsUsed(n,false); if(n == 0)return v; mute(v,a,n,num,IsUsed); return v; }};
0 0
- 【LeetCode】Permutations && Permutations II
- leetcode: Permutations/Permutations II
- leetcode Permutations & Permutations II
- [Leetcode]Permutations && Permutations II
- LeetCode: Permutations
- LeetCode: Permutations
- [Leetcode] Permutations
- [LeetCode] Permutations
- Leetcode: Permutations
- [Leetcode] Permutations
- [Leetcode] Permutations
- [LeetCode]Permutations
- LeetCode-Permutations
- [leetcode] permutations
- LeetCode - Permutations
- Leetcode: Permutations
- 【leetcode】Permutations
- 【LeetCode】Permutations
- Anti-Alias
- HTTP请求方式
- 判断是否为第一次登录
- Microsoft Azure 在北美 TechEd 大会上发布令人振奋的更新,帮助客户开始使用云服务
- 操作系统东西
- leetcode - Permutations
- C++拷贝构造函数详解
- keil错误提示Error: L6218E: Undefined symbol
- Python多线程(threading)学习总结
- 又要一次启航么!
- oracle数据库远程其他服务器
- hibernateTemplate与数据库的交互
- Ant报错之out of memory
- cad命令