LeetCode46:Permutations
来源:互联网 发布:网络虚拟市场 编辑:程序博客网 时间:2024/05/22 17:21
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].
全排列的问题,分析可以参考这篇文章
这道题目的题解:
class Solution {public: vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> result; premuteRe(nums,0,result); return result; } void premuteRe(vector<int> & nums,int offset,vector<vector<int>> &result) { if(nums.size()==offset+1) { result.push_back(nums); return ; } vector<int>::iterator base=nums.begin()+offset; vector<int>::iterator iter=base; for(;iter!=nums.end();iter++) { swap(*base,*iter); premuteRe(nums,offset+1,result); swap(*base,*iter); } }};
runtime:12ms
0 0
- LeetCode46:Permutations
- Leetcode46 Permutations
- leetcode46. Permutations
- LeetCode46 Permutations
- LeetCode46 Permutations
- leetcode46. Permutations
- LeetCode46——Permutations
- Leetcode46——Permutations
- leetcode46/47-Permutations I/II(全排列问题)
- Leetcode46: Power of Two
- leetcode46简单动态规划
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- Permutations
- ONOS发布1.2版本Cardinal——专注可扩展性
- Android设置界面切换动画的两种方式
- poj2709Painter
- 2 walks Once again
- vs2010/MFC Ribbon风格修改窗体标题
- LeetCode46:Permutations
- Spark以及SparkR的安装(standalone模式)
- 承志医疗管理系统技术解析出院步骤(八)
- Android 属性动画简介
- org.springframework.util.AntPathMatcher的使用
- iOS 多Bu工程解耦
- Centos 安装Ftp客户端和开启vsftp服务
- 学习rpmbuild总结
- Android换肤技术