[LeetCode] Permutations
2013-01-27 23:34
369 查看
class Solution { public: vector<vector<int> > ret; vector<int> sln; void DFS(vector<int> &num, vector<bool> &used, int n) { if (n == num.size()) { ret.push_back(sln); return; } for (int i = 0; i < num.size(); i++) { if (used[i]) continue; used[i] = true; sln.push_back(num[i]); DFS(num, used, n + 1); sln.pop_back(); used[i] = false; } } vector<vector<int> > permute(vector<int> &num) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<bool> used(num.size()); ret.clear(); sln.clear(); DFS(num, used, 0); return ret; } };
Small Case: 8ms
Large Case: 80ms
相关文章推荐
- leetcode-46 Permutations
- Permutations_Leetcode_#46
- LeetCode "Permutations"
- 【LeetCode】Permutations
- 【LeetCode】Permutations 解题报告
- Leetcode 46 Permutations
- Leetcode_permutations-ii
- LeetCode - 46. Permutations
- [leetcode] permutations的讨论
- LeetCode|Permutations
- 【LeetCode从零单刷】Permutations
- [LeetCode] Permutations (Find all permutations of a integer array w/ or w/o duplicates)
- Leetcode: Permutations 理解分析
- LeetCode-Permutations && unique && next
- leetcode 46. Permutations
- LeetCode题解——permutations
- [LeetCode]—Permutations 求全排列
- LeetCode Permutations II
- leetcode[46]Permutations
- Leetcode 46. Permutations & 47. Permutations II