LeetCode 数字排列问题 46 Permutations
2017-07-18 16:18
411 查看
题目链接
https://leetcode.com/problems/permutations/#/description
Given a collection of distinct numbers, return all possible permutations.
For example,
https://leetcode.com/problems/permutations/#/description
Given a collection of distinct 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], [3,2,1] ]
vector<vector<int>>permute(vector<int> nums) { vector<vector<int>> permutions; if(nums.empty()) return permutions; perm(nums,0,permutions); return permutions; } void perm(vector<int>nums,int start,vector<vector<int>>&permutions) { if(start == nums.size()) { permutions.push_back(nums); return; } for(int i = start;i < nums.size();i++) { swap(nums[start],nums[i]); perm(nums,start + 1,permutions); } }
相关文章推荐
- leetcode-46、47 Permutations/II 数字的排列组合
- LeetCode 46 47....排列问题
- [LeetCode] “全排列”问题系列(一) - 用交换元素法生成全排列及其应用,例题: Permutations I 和 II, N-Queens I 和 II,数独问题
- LeetCode- 46/47. Permutations/Permutations || (JAVA) (全排列1,2)
- LeetCode 46 Permutations(全排列问题)
- LeetCode—**字符串中数字的全排列问题Permutations
- Leetcode中的组合排列问题:Permutations,Combinations,Letter Combinations of a Phone Number
- [leetcode 46] Permutations------数组中元素的所有排列组合集合
- “全排列”问题系列(一)[LeetCode] - 用交换元素法生成全排列及其应用,例题: Permutations I 和 II, N-Queens I 和 II,数独问题
- 【leetcode 排列组合问题】Next Permutation | Permutations | Permutations II | Permutation Sequence
- leetcode46/47-Permutations I/II(全排列问题)
- leetcode[46]Permutations
- Leetcode46——Permutations
- leetcode | Permutations | 利用深度优先(DFS)的方法排列组合列表
- leetcode-46-permutations 搜索
- 【LeetCode】Permutations && Combinations 排列组合
- LeetCode:Permutations, Permutations II(求全排列)
- Leetcode-数字根问题
- leetcode之Permutations问题
- LeetCode 46 Permutations