LeetCode Permutations
来源:互联网 发布:透视眼软件 编辑:程序博客网 时间:2024/06/05 05:13
题目:
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<vector<int> > permute(vector<int> &num) {res.clear();memset(used, false, sizeof(used));dfs(0, num.size(), num);return res;}private:vector<vector<int> > res;bool used[100];int a[100];void dfs(int dep, int maxDep, vector<int> &num) {if (dep == maxDep) {vector<int> tt;for (int i = 0; i < maxDep; i++)tt.push_back(a[i]);res.push_back(tt);return;}for (int i = 0; i < maxDep; i++) {if (!used[i]) {used[i] = true;a[dep] = num[i];dfs(dep + 1, maxDep, num);used[i] = false;}}}};
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
- ACM-最短路之一个人的旅行——hdu2066
- HDU 1548
- Android详细的对话框AlertDialog.Builder使用方法
- Aptana3 使用不完全指南
- MongoDB 复制集模式Replica Sets
- LeetCode Permutations
- C++必知必会(3)
- 中国互联网少了周鸿祎将会怎样?
- 2014百度之星初赛(第二场)——JZP Set
- 网络编程TCP&UDP基础总结
- ubuntu 14.04 输入法
- Max Points On a Line--leetcode
- AlertDialog.Builder对话框类的用法
- 单纯的树