[leetcode] 46. Permutations
来源:互联网 发布:人脸比对系统源码 编辑:程序博客网 时间:2024/05/16 07:58
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]]解法一:
dp的思想,挨个生长随机数组。
class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int> > res; vector<int> first(1,nums[0]); res.push_back(first); for(int i=1; i<nums.size(); i++){ vector<vector<int> > tmp; tmp = permuteSub(res, nums[i]); res.clear(); res = tmp; } return res; } vector<vector<int> > permuteSub(vector<vector<int>> pre, int num){ vector<vector<int> > res; for(int i=0; i<pre.size(); i++){ int len = pre[i].size(); for(int j=0; j<=len;j++){ vector<int> tmp = pre[i]; tmp.insert(tmp.begin()+j, num); res.push_back(tmp); } } return res; }};
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
- HTML5学习(三)—4
- 抽象工厂模式
- Find the Duplicate Number
- 详解 ML2 Core Plugin(II) - 每天5分钟玩转 OpenStack(72)
- sklearn GMM
- [leetcode] 46. Permutations
- Xlib和GLX
- 学校oj显示在线用户数超过了序列号允许。您需要购买或升级您的序列号
- 【Leetcode】Ransom Note
- 求前n项和 , 要求不用乘除,循环,判断 (三种方法)
- 为了经济不顾安全?
- TIM_OCIdleState
- 勾股定理一日一证连载69
- 2016.08.11【初中部 NOIP提高组 】模拟赛C题目