leetcode[46]Permutations
2015-02-10 12:55
375 查看
Given a collection of numbers, return all possible permutations.
For example,
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: void perm(vector<int> &num, int i, int N, vector<vector<int>> &res) { if(i==N) res.push_back(num); for (int j=i;j<N;j++) { swap(num[i],num[j]); perm(num,i+1,N,res); swap(num[j],num[i]); } } vector<vector<int> > permute(vector<int> &num) { vector<vector<int> > res; perm(num,0,num.size(),res); return res; } };
相关文章推荐
- LeetCode 46 Permutations
- LeetCode46:Permutations
- Leetcode 46 Permutations
- LeetCode 46:Permutations
- LeetCode - 46 - Permutations
- LeetCode 46: Permutations
- LeetCode_46 Permutations
- leetcode-46-permutations 搜索
- [LeetCode 46 & 47] Permutations I & II
- LeetCode- 46/47. Permutations/Permutations || (JAVA) (全排列1,2)
- LeetCode-46 Permutations(全排列)
- 【LEETCODE】46-Permutations
- [Leetcode 53] 46 Permutations
- Leetcode-46: Permutations
- Leetcode 46 Permutations
- LeetCode_OJ【46】Permutations
- LeetCode 46: Permutations
- [LeetCode]46 Permutations
- Leetcode 46/47 Permutations, Permutations II
- LeetCode 46 Permutations