Leetcode 46. Permutations
来源:互联网 发布:unity3d 设置技能cd 编辑:程序博客网 时间:2024/05/14 03:48
题意
生成一个数组的全派别
题解
用递归实现。每个位置的数字都能和它后面的所有数字交换的,一共有n!种。
代码
class Solution {public: vector<vector<int> > result; void gen_permutation(int pos, vector<int> &nums) { if(pos == nums.size()) { result.push_back(nums); } else { for(int i = pos; i < nums.size(); i++) { swap(nums[i], nums[pos]); gen_permutation(pos + 1, nums); swap(nums[i], nums[pos]); } } } vector<vector<int>> permute(vector<int>& nums) { gen_permutation(0, nums); return result; }};
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
- isBalancedTree
- iOS Android音频格式的选择
- Android开发学习笔记:Intent的简介以及属性的详解
- 如何快速读懂别人的项目
- 大话数据结构读书笔记系列(三)线性表
- Leetcode 46. Permutations
- ZYThumbnailTableView类似于小型阅读器
- 360笔试题
- 数据结构与算法——RB树简介
- 博科SAN交换机:常用命令行
- HDOJ 2045 不容易系列之(3)—— LELE的RPG难题
- 欢迎使用CSDN-markdown编辑器
- Machine Learning机器学习公开课汇总
- drawable.setCallback(空)的后果