Permutations
来源:互联网 发布:swfobject.js 官网 编辑:程序博客网 时间:2024/06/07 05:30
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]
, and [3,2,1]
.
看完一遍题目应该就知道使用回溯算法,不过有个针对数组使用回溯的技巧,就是用swap函数来调换次序。
class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> result; ppp(nums,0,result); return result; } void ppp(vector<int>& nums,int begin,vector<vector<int>>& result) { if(begin >=nums.size()) { result.push_back(nums); return; } for(int i(begin);i<nums.size();++i) { swap(nums[begin],nums[i]); ppp(nums,begin+1,result); swap(nums[begin],nums[i]); } }};
0 0
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- 查看显卡的计算能力
- TabHost--选项卡案例
- Educational Codeforces Round 4 D. The Union of k-Segments(★)
- 仅有正反馈的op或连正反馈都没有的op电路
- java之输出字符到java(或txt)文件
- Permutations
- PC上安装Qt-Embedded
- 1——PHP常见的系统常量
- HDU1710-Binary Tree Traversals
- JS实现无缝滚动
- Problem C - Sums ACM/ICPC Central Europe Regional Contest 2014
- CentOS vsftp虚拟用户
- C++ 转换类型运算符 通过operator关键字进行转换
- 加载本地文件到Hive表出现NULL列的解决办法