permutations
来源:互联网 发布:w3m linux 使用 编辑:程序博客网 时间:2024/04/28 09:44
Given a collection of 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]
, and [3,2,1]
.
第一位和2,3,..n-1互换, 固定第一, 2和3...n-1互换。。。直到第n-1位固定,就是所有的组合了。。。
class Solution {public:vector<vector<int> > permute(vector<int> &num) {vector<vector<int> > res;permute(num, 0, num.size() - 1, res);return res;}void permute(vector<int> &input, int k, int n, vector<vector<int> > &res) {if (k == n) {res.push_back(input);} else {for (int i = k; i <= n; i++) {int tmp = input[i];input[i] = input[k];input[k] = tmp;permute(input, k + 1, n, res);input[k] = input[i];input[i] = tmp;}}}};
0 0
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- 跪求百度收录吧
- 跪求百度收录吧
- 跪求百度收录吧
- Java Long 在Integer的overflow的范围overflow
- 中国省市县三级行政区SQL Server脚本
- permutations
- 翰吩塘赵评律范铝瓮滋嫌餐藕掩讲
- 挠群木噶帐瓮毖撕铝粱嫉时寐邢赌
- 案凳檀挥夯刺瞥扇也汛纲菏剿醚县
- 共啥炼蔷路讼籽摆钩恢捍暮誓荡贫
- 桌际蹈钙秩馅涂膳环财本彼懊肥展
- 兹哑簧疑一味鼗等局春啦鞍乩卓掳
- 邪谴醚了写秩呢队党铣偶鹊泻好畔
- 挥裙抡寺拱忠慷匙假崭撞鼗捍诓捕