LEETCODE 46. Permutations
来源:互联网 发布:淘宝出货单表格 编辑:程序博客网 时间:2024/06/16 18:57
题目大意
给出一个数组,里面是各不相等的数字,求出所有可能的permutation。
如:
[1,2,3]
[
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
解题思路
假设数组
.
.
.
对于
当
具体实现的时候可以参考这个例子:
代码
class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> resVec; getPermutations(nums, 0, resVec); return resVec; }private: void getPermutations(vector<int> numArr, int startInd, vector<vector<int>>& res) { if (startInd >= numArr.size()) { res.push_back(numArr); return; } for (int i = startInd; i < numArr.size(); i++) { swap(numArr[startInd], numArr[i]); getPermutations(numArr, startInd + 1, res); swap(numArr[startInd], numArr[i]); } }};
0 0
- [LeetCode]46.Permutations
- LeetCode 46.Permutations
- 46. Permutations Leetcode Python
- LeetCode --- 46. Permutations
- [Leetcode] 46. Permutations
- [leetcode] 46.Permutations
- LeetCode 46. Permutations DFS
- 46. Permutations LeetCode
- Leetcode 46. Permutations
- leetcode 46. Permutations
- LeetCode *** 46. Permutations
- LeetCode 46. Permutations
- leetcode 46. Permutations
- LeetCode - 46. Permutations
- 【leetcode】46. Permutations
- leetcode 46. Permutations
- [LeetCode] 46. Permutations
- leetcode 46. Permutations
- vue 搭建
- 使用flex box(弹性盒子模型)进行页面布局的注意事项
- 远程linux数据库时无法正常连接的解决方法
- 查看cpu 频率hz
- 原生Android也能做Web开发了
- LEETCODE 46. Permutations
- SQL truncate 、delete与drop区别
- 特征选择之relief及reliefF算法
- 图片拼接
- android插件化(BroadCast、Service篇)
- 欢迎使用CSDN-markdown编辑器
- 网络编程:I/O复用
- UML图符号详解
- replace 第二个参数为函数的情况